GeeCON Prague 2014*
The moose likes Java in General and the fly likes Read Excel values and store in to Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Read Excel values and store in to Database" Watch "Read Excel values and store in to Database" New topic
Author

Read Excel values and store in to Database

Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
The following code will read Excel sheet and print it to console, i want to read excel values and store in to Database.
Can you give me logic to read cells and store in to DB



Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Rajendra Prakash wrote:Can you give me logic to read cells and store in to DB

No it doesn't work that way. What have you tried? What went wrong? What happened and what did you expect to happen?

And moving to Java in General.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
From Excel sheet i read all the fields as string . In that date field is there , i am getting "dd/mm/yyyy" format.
But i want to convert this to "yyyy/mm/dd". i have tried with SimpleDateFormat class. But i could not get.
can you help me
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 513
Hi,
Why did SimpleDateFormate not work? Did it throw any exception or did not convert the date in the format you needed.
Let us know.

regds,
Amit
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
with the following code i can read multiple excel files in a single workbook and store in to database. Now
i want to read multiple workbooks and store in to db. can you give me any logic for this.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42033
    
  64
Now i want to read multiple workbooks and store in to db. can you give me any logic for this.

There is a method that reads one file and stores something to the database - it sounds as if calling that method multiple times with different files would do the trick. Have you tried that? If so, what was the result? If not, tell us where you are stuck making progress.


Ping & DNS - my free Android networking tools app
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
No am not clear what you say. consider two folders , each consists one workbook . i want to read both workbooks and store in to db
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42033
    
  64
Well, the "first" method reads one file and stores it to the DB, no? What is the problem with calling xlreader.first(..) repeatedly with different filenames?
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
yes , it is working fine. Now user can select workbook dynamically means , what i can do.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42033
    
  64
I don't follow - what difference does it make whether the user selects the file, or if the filename is hardcoded? The Excel/DB part would be the same, no?

If you're asking how a user can choose a file, start here: http://download.oracle.com/javase/tutorial/uiswing/components/filechooser.html

If you're asking something else, TellTheDetails. Your last two posts were very short, so it's hard to know what you have, and what problems you're encountering.
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
consider i have a folder prakash,inside that i would like to find all excel files . Once i found all excel files i have read the same and store in to db
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42033
    
  64
OK, that's not hard. What do you have so far, and where are you stuck making progress? Are you familiar with the java.io package, particularly the File class and its methods? If not, that's where you should start.
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
with the following code i can read multiple excel files. but now i want to read multiple excel files from single folder in
a single line. i dont want to call "first" method again and again. which means i want call excel file dynamically


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42033
    
  64
but now i want to read multiple excel files from single folder in a single line. i dont want to call "first" method again and again. which means i want call excel file dynamically.

Create a method that takes the name of the directory as parameter, and in that method iterate through all files in that directory. For each xls file you'd then call the first method.
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
consider i have some 3 or 4 excel files.I dont know that files names , how can i read all files one by one
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42033
    
  64
The java.io.File class has methods for enumerating all files in a directory. You can then check their names in a loop, and only process those with appropriate file names (like with an "xls" extension).
 
GeeCON Prague 2014
 
subject: Read Excel values and store in to Database