• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Empty database when using for statement

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 https://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.
 
Ranch Hand
Posts: 144
Oracle Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Runs fine now, thanks for your help. (still not sure what was wrong with my first do/while loop though )
reply
    Bookmark Topic Watch Topic
  • New Topic