0

I want to count the total no of rows in a table

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection con = DriverManager.getConnection("jdbc:odbc:gabbar");
  Statement ps1 = con.createStatement();
  ResultSet count = ps1.executeQuery("SELECT COUNT (*) FROM products );
//products is a table in database

count is of ResultSet type.but i want to do arithmetic operation on count variable.i want count to be in int datatype.what should i do?
i dont know how to solve this problem

5
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by stultuske
0

I'm looking at the documentation and I don't see a way to "executeScalar" -- which is what I think you're looking for.

One technique you could use is to put that stuff in a function, get the count the hard way and return it as a long. That way, you can use it (by masking it) as a direct result.

0

Well count any not null column in the table. Then the below code will help u.

if(resultset.next())
long count = Parse to Long (resultset.getString("columnname"));
0

Use Integer.parseInt() function . It takes String as parameter

Edited by DJSAN10: n/a

0

use the
int getInt(int columnIndex)
Retrieves the value of the designated column in the current row of this ResultSet object as an int in the Java programming language.

method of ResultSet.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.