Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes save Excel data to database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "save Excel data to database" Watch "save Excel data to database" New topic
Author

save Excel data to database

Nash kumar
Greenhorn

Joined: Sep 23, 2012
Posts: 20
I am a java beginner. I have the below file that reads excel file. Excel file has nine columns and I created a DB Table with 9 columns. I would like to read the excel file except the first row and write to database table. How to achieve this.



J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 634
    
    7

There are probably several ways to do this, but personally, I would create a JavaBean that represents each of the columns in your database record, populate that bean with the values you've pulled from the spreadsheet, and then pass that bean to a DAO that will do the insert or update.

That's just my two cents worth. I'll be interested in seeing what other solutions are recommended.


"There is no reason for any individual to have a computer in his home" ~ Ken Olson, Co-founder of DEC, 1977
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18167
    
    8

Yes, there are many different ways of arranging for your data to be written to a database.

But none of those ways are going to care that you got that data from an Excel spreadsheet. In other words, the fact that your data came from Excel is irrelevant. Once you've got it out of Excel, just pick one of those ways and write the data to the database.

If you don't know any ways of writing to a database, let me recommend the JDBC tutorial.
Nash kumar
Greenhorn

Joined: Sep 23, 2012
Posts: 20
Thank for the reply. I know how to use JDBC to insert values. Please help me how to save each cell value into a variable in order to insert them. Thank you.
J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 634
    
    7

What have you tried so far? Exactly what are you not clear on?

Show us some code. I think we've given you enough to at least take a stab at it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: save Excel data to database
 
Similar Threads
resultsetmetadata
excel sheet data insertion
How to import data from Excel sheet to database using java??
Apache POI column Iternator
reading multiple sheets using apache POI