wood burning stoves 2.0*
The moose likes JDBC and the fly likes SQL ResultSet count Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL ResultSet count Problem" Watch "SQL ResultSet count Problem" New topic
Author

SQL ResultSet count Problem

Sivaraman Lakshmanan
Ranch Hand

Joined: Aug 02, 2003
Posts: 231
Hi all,
I wrote a SQL query which is a join between 2 table, which has also got group by functions etc. The Query executed perfectly in the DB. I am using MSAccess as the Database. The query returned 4 rows and 2 columns which is correct. So everything is fine on the DB side.
When I executed the same query in Java, using JDBC, I used a scrollable resultset. I want to convert this Resultset in to a 2 dimensional String array. So I found the number of rows by scrolling through the resultset and incrementing a int variable. The Funniest thing is instead of return 4 its returning 12. That is it say there are 12 rows but as per the query results on the DB side there are only 4 rows. How is this possible.
But when I did the same thing using PreparedStatement, without scrolling resultset I am getting correct results. Can anyone please explain me why this is happening
Any help on this is very much Appreciated


Regards,
Sivaraman.L
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
I have no idea, and I haven't used Access from JDBC or scrollable result sets. I can, however, tell you that others will be more likely to help if you post your code, the query, the driver you're using, and the JDK version. Also, are you running this in a straight Java application or from within a J2EE container like Tomcat, WebLogic, JBoss, etc?
Sivaraman Lakshmanan
Ranch Hand

Joined: Aug 02, 2003
Posts: 231
hi all,
I am using Just Textpad to run the program as an application. The Java version is 1.4.1_02. I am pasting my code here.



Error I got


This query has to return only 4 records but I am not sure why the
rs.next() is still giving true even after the 4th record.

Regards,
Sivaraman.L

[edited to add line break in query so page doesn't scroll right]
[ January 29, 2005: Message edited by: Jeanne Boyarsky ]
Hareesh Ram Chanchali
Ranch Hand

Joined: Jan 31, 2005
Posts: 110
hi sivaraman,

plz visit following link for ur information about count no. of rows of RS

http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/rs/CountResult.html

hope it will help u alot

plz tell me ur solution


Hareesh Ram Chanchali
SCJP 5.0, IBM Certified Solution Designer
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SQL ResultSet count Problem