In mysql command line, when i give the command:
select count(*) tables from users;
it works correctly. It gives me the size of the table.
But, i want to take the result in Java file.Thus i write in Java file the below code.But it doesn’t work
public int f()
{
ResultSet rs;
int i;
String query = "select count(*) tables from users";
Statement st = this.con.createStatement(); //error
rs = st.executeQuery(query); //error
if(rs.next()) //error
{ //error
i = rs.getInt(1); //error
}
return i; //error
}
How can i get the size of table in my Java file?
you never checked if the resultSet has data using its next() method.
From ResultSet API:
also
ResultSethasgetInt()method notGetInt(), java is case sensitive.EDIT: you have to handle or declare SQLException(checked exception) in your code. Connection.createStatement() would throw SQLException.