Solved

Recordset counter

Posted on 1997-06-05
5
1,999 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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:
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:

717 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