SQL SELECT result
try{
// Create a result set containing all data from my_table
Statement s = connection.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM station WHERE stationID = '" + stationID +"'");
}catch (SQLException e){
}
If there are no rows for that SQL statement, what will it return back to me? On my server, a client is sending a packet to me that contains the stationID. First, I want to make sure stationID already exists in the database. If it doesn't exist, I would like to run more SQL statements, but first I need to know what it will return to me.
In guessing code, this is what I'm looking for:try{
// Create a result set containing all data from my_table
Statement s = connection.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM station WHERE stationID = '" + stationID +"'");
if (rs == NULL)// if no rows were selected
{
// if there were no rows selected from the original SELECT statement, INSERT a new row using this query
ResultSet rs = s.executeQuery("INSERT INTO station VALUES ('stationID', 'address', 'city', 'state', zip'");
}
}catch (SQLException e){
}
Any help?
Message was edited by:
tristanlee85

