How do I tell if a row exists in a table?

java, jdbc, sql

Solution

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
}

Problem

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.

Original source