uploading Excel using POI

hello ,

i want to read excel file which user is going to upload from browser and copy data in database .

I go through various forums and as per information write some code .

using POI apis

I am new to POI apis

and my code is giving me FileNotFound Exception.

what may be wrong !!

regards ,

amol

[349 byte] By [JAmola] at [2007-10-3 0:13:59]
# 1
can you post the code (the block that give FileNotFound exception)Most probably you are trying to load a file that is not there. Normally when you dealin with file uploads you might want to initialize a work book from the incomming input stream. not from files
LRMKa at 2007-7-14 17:04:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

// jsp code

<form name = "frm1" method = "post" enctype="multipart/form-data">

<input type = "file" name = "uploadme">

<INPUT TYPE="submit" >

</form>

// java code

POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(request.getParameter("uploadme")));

//#### above statement giving me an error

HSSFWorkbook wb = new HSSFWorkbook(fs);

HSSFSheet sheet = wb.getSheetAt(0);

HSSFRow row = sheet.getRow(0);

HSSFCell cell = row.getCell((short)0);

System.out.println("->" + cell.getStringCellValue());

regards,

amol

JAmola at 2007-7-14 17:04:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

A FileInputStream is used to input data from what your operating system calls a file. That's a file on your hard drive, in other words. You can't use it to input data from an HTTP file upload.

I recommend using Apache Commons FileUpload. Read its examples to find out how to access an uploaded file from an HTTP request. Like LRMK suggested.

DrClapa at 2007-7-14 17:04:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
when you are using request.getparameter() it is giveng Null..that is the reason for the ErrorMake sure that you read the Entire path of the particular Fileand tryWith RegardsChandu
Sambarapua at 2007-7-14 17:04:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Thanks u for your help,

I found the error by reading more on forum / tutorial,

if I use

enctype="multipart/form-data"

as property of form tag

then

request.getparameter() is giving null ,

proper way, is to use following line of code and proceed further

MultipartRequestParser mrp = new MultipartRequestParser(request, System.getProperty("user.dir") + System.getProperty("file.separator"));

InputStream xlFile = new FileInputStream(mrp.getFileName());

JAmola at 2007-7-14 17:04:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...