For example:
select name from person where id=2;
I wand to know if this row exists, and depending on its existence perform a certain task. I wan to do this using jdbc.
To select rows using selection symbols for character or graphic data, use the LIKE keyword in a WHERE clause, and the underscore and percent sign as selection symbols. You can create multiple row conditions, and use the AND, OR, or IN keywords to connect the conditions.
SQL NOT EXISTS in a subquery NOT EXISTS is used with a subquery in the WHERE clause to check if the result of the subquery returns TRUE or FALSE. The Boolean value is then used to narrow down the rows from the outer select statement.
Use PreparedStatement
to invoke this select query,
After the successful execution of query you would have instance of ResultSet
returned, you could check by invoking next()
if it returns true it means there was a row selected
if(resultSet.next()){
//yes exist
}
The is no hasNext() method in ResultSet. The next() method moves the cursor to the next row and if there is a row then it returns true.
if(resultSet.next()){
//do something
}
else{
//no next row found
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With