Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

database query size

Status
Not open for further replies.

riches85

Programmer
Nov 13, 2002
59
US
If I execute a query in java, is there a way to determine the number of results without looping through the entire result set?
 
Unlikely.You have to find some other ways to find the number of records for that.DB2 with versions 7.1 and higher,gives the record number of an query with a function for example.

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
turkey_clr.gif
 
Hi,

If you are looking for the size of the Resultset then you can use getFetchSize() of Resultset. Did I understood your question correctly ?

Cheers
Venu
 
Please examine this code below:
try{
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
String url = "jdbc:db2:OGER2002" ;
java.sql.Connection connection = java.sql.DriverManager.getConnection(url, "db2admin", "db2admin");
java.sql.Statement stmt =connection.createStatement();
java.sql.ResultSet rs = stmt.executeQuery("select * from genparam.citylist");
System.out.println(rs.getFetchSize()+ "Fetch Size");
int i = 0;
while (rs.next()){
System.out.println(++i);
}
}
catch (Exception ex){
System.out.println(ex.toString());
}

That is taken from my database OGER2002 and genparam.citylist table.
Here is the console print messages of the code.
1Fetch Size
1
2
3
4
5
6
7
8
9
10
11
goes to 42 ( I didnt write it down up to 42 of course here)
the fetch size DOES NOT give you the number of records.
And size of a row DOES NOT mean the number of records also.
You can find number of columns,tables,foreign key by ResultSetMetaData but NOT this.

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
turkey_clr.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top