[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Recordset counter

Posted on 1997-06-05
5
Medium Priority
?
2,004 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 100 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

656 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