I got part of my answer from Is there any sql-query to check the value is exist or not in db table
In the comment of Paraíso
But I can't copy the return value to a boolean variable. It gives an error as
SEVERE: null<br>
java.sql.SQLException: Invalid operation at current cursor position.
My code:
String sel="select CASE WHEN count(1) > 0 THEN true ELSE false END from ledgerslist where ledger = 'dera'";
PreparedStatement stc=conn.prepareStatement(sel);
ResultSet rsk=stc.executeQuery();
Boolean cc=false;
cc=rsk.getBoolean(1);
conn.close();
System.out.println(cc);