whether it is posssible to get the count value in a variable .please reply.
Printable View
whether it is posssible to get the count value in a variable .please reply.
Yes. I assume you mean the count of records in a database.
select count(*) from SomeTable where SomeCondition
Execute this query and use the ResultSet to retrieve the count.
In any method use an integer as a count this is a sample code:
public void.....{
int count=0;
try
{
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM any table");
while(rs.next())
{
count++;
}
System.out.println(count);
then you will get the number of records.
What if the table contain 1,000,000 records? I've worked with tables that had 40 million, and they were archived annually. Looping through all those records could take minutes to hours.
[CODE]
public int getRecordCount {
int count=0;
try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT count(*) FROM table");
if (rs.next()) {
count = rs.getInt(1);
}
}
return count;
}
rs.last();
int count= rs.getRow();
this will get the current row number, which is the last in your table, i hope it will work.