File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Empty database when using for statement" Watch "Empty database when using for statement" New topic
Author

Empty database when using for statement

Jasper Brown
Greenhorn

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.


OCJP6, OCWCD5
Jasper Brown
Greenhorn

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 )
 
 
subject: Empty database when using for statement