I am trying to execute following code. Connection is being built successfully.
String selectq = "select max(id) as max_id from items";
currentCon = (Connection) ConnectionManager.getConnection();
stmt=(Statement) currentCon.createStatement();
ResultSet rSelect = stmt.executeQuery(selectq);
On executing following command, output is coming as 1 even if there is no row in the table.
rSelect.next();
System.out.println(rSelect.getRow());
My requirement is to check if there are no records in the table, otherwise I need to get the max of id column from that table.
I have tried many things like
rSelect.last();
rSelect.next();
But, I am not able to get the required result.
I am using
- Eclipse Indigo 3.7
- JDK 1.6.0_37
- Tomcat 7
- MySQL
It worked after adding a If statement like below:
Since, there can exists only one row or nothing according to my query.