In Java, there are several ways to get the total number of rows in resultset.
First: Use ResultSet's GetRow method to get the total number of resultset
Statement stmt = con.createstatement (resultset.type_scroll_insensitive,resultset.concur_updatable);
ResultSet RSet = Stmt.executequery ("SELECT * from Yourtablename");
Rset.last ();
int rowCount = Rset.getrow (); Get total rows for resultset
The second type: Use the elements of the loop resultset to get the total number of resultset
ResultSet RSet = Stmt.executequery ("SELECT * from Yourtablename");
int rowCount = 0;
while (Rset.next ()) {
rowcount++;
}
RowCount is the total number of resultset.
Third: Use the Count function in the SQL statement to get the total number of rows in resultset
ResultSet RSet = Stmt.executequery ("SELECT count (*) TotalCount from Yourtablename");
int rowCount = 0;
if (Rset.next ()) {
Rowcount=rset. GetInt ("TotalCount");
}
RowCount is the total number of resultset.
Fourth: The total number of columns in Java that gets resultset is a very simple thing, because Java ResultSet provides ResultSetMetaData tool classes, ResultSetMetaData is a collection of resultset metadata descriptions.
Statement stmt = con.createstatement (resultset.type_scroll_insensitive,resultset.concur_updatable);
ResultSet RSet = Stmt.executequery ("SELECT * from yourtable");
ResultSetMetaData RSMD = Rset.getmetadata ();
int columnCount = Rsmd.getcolumncount ();
Both: ColumnCount is the total number of columns of resultset.
Java resultset get Total rows