File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL ResultSet count Problem

 
Sivaraman Lakshmanan
Ranch Hand
Posts: 231
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David Harkness
Ranch Hand
Posts: 1646
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 231
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic