jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes Empty database when using for statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Empty database when using for statement" Watch "Empty database when using for statement" New topic

Empty database when using for statement

Jasper Brown

Joined: May 31, 2011
Posts: 3
Hi, i'm new to java and am trying to build a database program about boats which needs to output a .csv file. I have it all working except for one issue. It runs fine as shown below and, as expected, only outputs the first record. When i 'uncomment' the for statement it gives the error 'no data found' at line 205 (the first line that tries to access the database) during the second iteration. I know the database has data because it works without the for statement. I originally tried to do this with a do/while statement but that gave an invalid string or buffer length error which is unsolvable (see http://www.coderanch.com/t/491407/JDBC/java/Mircrosoft-Driver-Manager-Invalid-String). (I am running it on a windows 7 64 bit system).

The database has more than one record and should return null if there is no data in the field. The numrows value is correct and is found by moving the pointer to last then getRow() then moving it back using first().

Any help is much appreciated.
Mike Zal
Ranch Hand

Joined: May 04, 2011
Posts: 144

You should not be calling the a flush method inside of a loop. You should never call flush until you are done adding to a writer. Secondly you should be using the next() method to iterate over a ResultSet.

Jasper Brown

Joined: May 31, 2011
Posts: 3
Runs fine now, thanks for your help. (still not sure what was wrong with my first do/while loop though )
I agree. Here's the link: http://aspose.com/file-tools
subject: Empty database when using for statement
It's not a secret anymore!