GeeCON Prague 2014*
The moose likes JDBC and the fly likes retrieving data from a databse into an excelsheet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "retrieving data from a databse into an excelsheet" Watch "retrieving data from a databse into an excelsheet" New topic
Author

retrieving data from a databse into an excelsheet

Komal Amaresh
Ranch Hand

Joined: Oct 06, 2008
Posts: 67
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

Joined: Dec 31, 2004
Posts: 961
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

Joined: Oct 06, 2008
Posts: 67
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

Joined: Feb 24, 2006
Posts: 6661
    
    5

Build a BIRT report and extract the output to a CSV file.

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

No coding required.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Ryan Webb
Greenhorn

Joined: Dec 09, 2009
Posts: 28
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


frustrated to learn c/c++/objective-c
Komal Amaresh
Ranch Hand

Joined: Oct 06, 2008
Posts: 67
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

Joined: Oct 06, 2008
Posts: 67
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

Joined: Dec 14, 2009
Posts: 133
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

Joined: Dec 14, 2009
Posts: 72
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..


They say you have to be the first, the best or different. I say, is it too much to ask for all three.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: retrieving data from a databse into an excelsheet