File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes A little help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "A little help" Watch "A little help" New topic

A little help

Ryan Raina

Joined: Jun 16, 2010
Posts: 28
Hi Friends i would like to have a little help!!
I have a situation that when a user uploads an excel the cells values need to persisted in the
database using insert querries in a for loop.
i am able to retrieve the cells values using Apache POI but
i donot know how to fire the querries
Kindly see my code below

what can i do to fire queries in database.??

Thanks in Advance
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
If you aren't familiar yet with JDBC -the standard Java API for accessing databases- then that's where you should start. Do you know which DB you will be using?

As an aside, you should write POI code using the classes in the package, not the *hssf* or *xssf* packages. That way the code can handle binary files as well as XML files.
Joshua Barrett

Joined: Sep 08, 2010
Posts: 27
You need to be more specific about the type of database you are using. I also assume you are familar with basic SQL

Also may I recommend you write a better title for your thread. Saying "A Little Help!" is not at all descriptive to your problem.
Ryan Raina

Joined: Jun 16, 2010
Posts: 28
Well i guess that i wan't clear on my question
If you see these lines of code you will find out that i am getting values of the cells as a output.

for (int j = 0; j < cellStoreVector.size(); j++) {
XSSFCell myCell = (XSSFCell) cellStoreVector.elementAt(j);
st = myCell.toString();
System.out.println(st); //prints the cell value for a row one by one

Now consider an example that there is an excel having header like name,address etc
the value of first cell on row 1 is under name and values of second cell is under address
on row 1.
Also database has these two columns
Now coming to the situation,
I need to fire some queries in database using insert statment
For example
Insert into tableNAme name,address values 'value of cell at row1 coloum1','value of cell at row1 coloum2'

ok now suppose there are lots of rows in the excel sheet
Then i have to do this same thing in a for loop.

so my question is this how should i approach to fire insert queries in a for loop
i have all the cell values in a list . how should i fire queries and also change the cell and column

I agree. Here's the link:
subject: A little help
It's not a secret anymore!