Solved

Recordset counter

Posted on 1997-06-05
5
1,997 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Groovy problem when using SOAPUI : DispatchException occurred 7 58
Unhandled exception type Exception 18 42
Running JavaFX on JDeveloper 12C 1 51
CSV file parsing thru Java 13 34
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

791 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