Results 1 to 5 of 5
- 01-21-2009, 08:41 AM #1
Member
- Join Date
- Jan 2009
- Posts
- 15
- Rep Power
- 0
- 01-21-2009, 05:00 PM #2
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.
- 01-23-2009, 08:18 AM #3
Member
- Join Date
- Jan 2009
- Posts
- 4
- Rep Power
- 0
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.
- 01-23-2009, 03:33 PM #4
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;
}
- 01-23-2009, 09:39 PM #5
Member
- Join Date
- Jan 2009
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
to get count value as a variable
By arunkumarinfo in forum JDBCReplies: 2Last Post: 03-30-2009, 01:32 AM -
count variable is not incrementing for the last comparison of the arrays
By raj reddy in forum Web FrameworksReplies: 1Last Post: 05-29-2008, 06:36 PM -
Getting row count
By Java Tip in forum Java TipReplies: 0Last Post: 02-11-2008, 08:49 AM -
how to count 2 inserts together?
By kim85 in forum New To JavaReplies: 0Last Post: 01-20-2008, 11:25 AM -
Getting row count from executeQuery()
By Java Tip in forum Java TipReplies: 0Last Post: 12-05-2007, 02:31 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks