After executing a JDBC query, you often want to know if anything was returned and if so how many rows exist in the ResultSet
. To do that, use this snippet of code:
ResultSet rs = st.exeuteQuery();
rs.last();
int rsRowCount = rs.getRow();
rs.beforeFirst();
The rsRowCount
variable will have the answer.
Make sure that your Statement
or PreparedStatenent
are created using the three parameter version of the Connection
object methods createStatement()
and PrepareStatement()
like:
Statement statement =
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
OR
PreparedStatement ps = conn.prepareStatement([SQL EXPRESSION],
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
Look at
the JavaDoc entry for this method.