• 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

retrieving data from a databse into an excelsheet

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In my application on leave management, I need to retrieve the data from the database into an excel sheet. I have no clue how to do this. Please help me in this regard. I have never worked on such an application before.

Thanks in advance,

regards,
Komal
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, there is not a simple answer to that.

Do you know how to access a database with Java and retrieve data from it? Have you ever used JDBC or any other ORM tools like iBatis, TopLink, Hibernate or any other library of this sort?


For converting data from your database into an Excel file you might consider Apache POI
 
Komal Amaresh
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Man, I' ve never heard of these.
But I have to do this.
Can you provide me with some code to work it out please.

Thanks,
regards,
Komal
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Build a BIRT report and extract the output to a CSV file.

http://eclipse.org/birt/phoenix/

No coding required.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello try this pseudo code...I just want to share the idea on how to do it manually in java. (since you're asking for code)...please apply proper exception handling and debug...(i only do in in text editor)



Hope this helps,
Ryan Webb
Philippines
 
Komal Amaresh
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ryan,

Thanks, for the code.
But, the excel sheet generated is blank. It is not retrieving the values from the table.
I' am using MySQL. I have changed the driver name and the url in the code.

Its generating a blank excel sheet. No data. Where is the problem. I can't make out.
The number of columns in my table are 5.
So I have changed the column count to 5 in the condition above.

Please help me.

Thanks and regards,

Komal
 
Komal Amaresh
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I' am unable to retrieve the data in my code.
The excel sheet is getting created fine. But the values are not added to th excel sheet.
I created a class which sets and gets the values for the different parameters. Further I' am creating a vector to store the values and have retrieved the values from the vector to print them.

The code' s like this:

setter getter class:

And I'am passing the values to the printWriter

but to no avail.
Please help me.

regards,
Komal

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can write data in excel sheet using file writer. You should have to use Apache POI to write data in excel format. There are lot of information available on internet.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Komal,

You forgot to flush the PrintWriter. Add this in the last line of your for loop.

pw.flush();

Dont forget to close the PrintWriter before exiting the code.

pw.close()

Hope this helps..
reply
    Bookmark Topic Watch Topic
  • New Topic