• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

retrieving data from a databse into an excelsheet

 
Komal Amaresh
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • 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
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • 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.
 
Ryan Webb
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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

 
xsunil kumar
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • 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.
 
Sandeep Sanaboyina
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • 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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic