permaculture playing cards*
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
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
Bartender

Joined: Dec 16, 2010
Posts: 1003
    
  13

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.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18672
    
    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
Bartender

Joined: Dec 16, 2010
Posts: 1003
    
  13

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: save Excel data to database