[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

JSP/Strut/Servlet - load the excel file to the data via Servlet

Posted on 2007-08-06
8
Medium Priority
?
447 Views
Last Modified: 2013-11-24
I need to create aJSP page which allows the user to select the Excel file from the PC dialog window and load to the database.

Would anyone give me any idea how to do it or point any web sites which provides a simple program?


Please advise.
0
Comment
Question by:LeanMoreTryMore
  • 5
  • 3
8 Comments
 
LVL 14

Expert Comment

by:boonleng
ID: 19643020
The following is a sample code to upload image to server and store to database, you can use it for other file types.
Make sure the table column for storing the file is "blob" type.

http://forum.java.sun.com/thread.jspa?threadID=5193481&messageID=9760508
0
 

Author Comment

by:LeanMoreTryMore
ID: 19643379
Thanks.
But i need to know how to select the excel file and then read and load the data frome excel to the database.
is it possible to do it?
0
 
LVL 14

Expert Comment

by:boonleng
ID: 19644091
> But i need to know how to select the excel file and then read and load the data from excel to the database.
i> s it possible to do it?

If you need to read the data from the excel file, then you need to use POI (http://poi.apache.org/).
The following consist sample to code to read excel file:
http://poi.apache.org/hssf/quick-guide.html
http://www.onjava.com/pub/a/onjava/2003/04/16/poi_excel.html

The previous link posted consist the full flow to upload the excel to server and insert to database. You just need to modify the struts action to use POI to read the uploaded file and insert to database.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:LeanMoreTryMore
ID: 19650882
boonleng,
The previous link posted consist the full flow to upload the excel to server and insert to database
Which one?
0
 

Author Comment

by:LeanMoreTryMore
ID: 19650903
I can under how to create the excel file. But i dont understand how to read the excel file.
How do i read a particular CELL in the excel file?

Regards
0
 
LVL 14

Accepted Solution

by:
boonleng earned 2000 total points
ID: 19651184
> Which one?
http://forum.java.sun.com/thread.jspa?threadID=5193481&messageID=9760508

FileUpload.jsp - This file allow user to select and upload file.
ImageFileUploadAction.java - This file process the uploaded file.
BModelServiceImpl.java - This file insert the data to database.

Although is use for uploaded image, but the code can use for all others file type.
For you case, you need to check the content type "application/vnd.ms-excel" instead of "image/jpeg".

> How do i read a particular CELL in the excel file?
The following sample code on how to read excel file is from the above link posted (with a bit modification).

POIFSFileSystem fs = new POIFSFileSystem(fileInputStream); //pass the uploaded file input stream to POI API.
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(2);
HSSFCell cell = row.getCell((short)3);
String value = String.valueOf(cell.getCellValue()); // Retrieve the cell value.
0
 

Author Comment

by:LeanMoreTryMore
ID: 19651925
Thanks boonleng
This is enough for me to go on for the time being.
0
 

Author Comment

by:LeanMoreTryMore
ID: 19651929
Thanks for the help
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
A solution for Fortify Path Manipulation.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question