Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Store column data in ArrayList for every row

 
Sanju Sanjana
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Guys,
I'm trying to fetch the data from database to an excel Sheet. I wanted to store the data by iterating through loops for columns for every row.I tried the following code but it's giving me an error as the columns are being overriding for every row. Thanku for the hep in advance





How to get the column data for every row?
 
J Steven Perry
Greenhorn
Posts: 13
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't run the code, but it looks like it might work. It looks like you are using perhaps POI to create a MS Excel spreadsheet? (Just curious)

One thing I noticed: you have a call to rs.next() just before your while loop. Because of this, you are always processing the second row in the result set first. If your result set only has one row, your loop will never be executed, and this could be causing the behavior you describe.

It is possible that the JDBC driver you are using does not correctly implement the ResultSetMetadata object that is returned from the call to rs.getMetaData()? You may try printing out the number of columns, just to see if it's returning zero or not (which, btw, is also possible).

It's also possible that your query doesn't return anything.

If not, can you expand on what exactly is wrong? It's not clear what you mean by "...as the columns are being overriding for every row."

HTH,
--jsp
 
Paul Clapham
Sheriff
Posts: 21576
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's also not clear what "it's giving me an error" means.

Have a look at our FAQ entry TellTheDetails (<-- click on that link) which explains how to post an answerable question.
 
Sanju Sanjana
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, perry am using Apache POI to create an excel. I have used rs.next() before while loop maybe this is causing the issue. I'm working on it !! Thanks for your suggestion

@ Paul Sorry! i will be clear from next time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic