Solved

Recordset counter

Posted on 1997-06-05
5
1,993 Views
Last Modified: 2012-08-14
    Class.forName("java.jdbc.odbc.JdbcOdbcDriver");
     String url = "jdbc:odbc:NortonDB";
       
     conDB = DriverManager.getConnection(url, "admin","");
     Statement stmt = conDB.createStatement();
     ResultSet rs = stmt.executeQuery(QueryLine);
       
     
//recordsetCount=(rs.getMetaData()).getColumnDisplaySize(1);

Hello,
The above line of code (that is commented out) is not doing what I want it to.  It returns some weird number that is definitely not the number of entries in a particular queried recordset.  I need to know how many entries are in a recordset I am querying.
  I am using an MS Access database and Odbc bridge.  The code is in an application written in java. I have no trouble with getting the info, but it would be nice to know  how many items are in the recordset.  So what is the call I need to make after I execute my Query?  'getRecordsetSize()'  would be nice.
Please give me a full answer. Thank you.
Georg Haugland
HyperGraphics
georita@iglobal.net
0
Comment
Question by:georita
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
jpk041897 earned 50 total points
ID: 1221271
GetRecordsetSize is not supported by all ODBC drivers, as an alternative, add a Count statement to uour SQL call.

The Count collumn will contain the number of records retruieved (generated by the DB server not the ODBC driver) and is guaranteed to work across all ptatforms and drivers.

For instance

SELECT FIELD1, FIELD2, COUNT(*) FROM table WHERE FIELD1 =17;
0
 

Author Comment

by:georita
ID: 1221272
How do you retrieve the count after the call is made?  Is there a call to a particular part of the ResultSet object, or what?   I am still not understanding the source of the count that  I could then use in a interger variable.
0
 

Author Comment

by:georita
ID: 1221273
My query is only one field at a time anmd cannot use the count in the SQL call.  
Here is an example call:
"select QuestionID from Question"
This was your suggestion, and it gives me an error.

"select QuestionID, count(*) from Question"

I am putting the results into an array and I must know the size of the ResultSet before I can do it correctly.  Please advise.
Georg Haugland

0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1221274
If you need the number of records before you fetch, you will have to run the querry twice. Assuming,of course, that your driver does not support getRecordsetCount.

Make the first call

"select count (QuestionID) from Question"

The result set should contain a single number value that contains the number of QuestionID rows in the table.

then run your querry to retrieve the record set.

Alternativley, Use the Querry Design View in Access and create your querry, including a count , then press the View Button and click SQL view.  That will produce the SQL statement that you require.

As a final alternative, you could save the previous querry and use it as a stored procedure.
0
 

Author Comment

by:georita
ID: 1221275
Excellent answer!!!
I thank you for your time
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count8 challlenge 13 87
pairstar challenge 2 42
solarwind tftp server 2 32
HSSFWorkbook cannot be resolved error 10 23
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now