I tried different ways to get the number of rows in java JDBC, the nut seems to be giving the correct result. Is something wrong, what am I doing?
Even though the client table is empty and I have to get the row value as 0, I donβt understand why I get a non-zero rowcount value.
Method 1 -
query = "SELECT * FROM customer WHERE username ='"+username+"'"; rs = stmt.executeQuery(query); ResultSetMetaData metaData = rs.getMetaData(); rowcount = metaData.getColumnCount();
Method 2 -
query = "SELECT * FROM customer WHERE username ='"+username+"'"; rs = stmt.executeQuery(query); rowcount = rs.last() ? rs.getRow() : 0;
java jdbc
Student
source share