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

Unable to get connection


Joined: Jul 25, 2008
Posts: 6
I have a jsp page that allow user to upload excel file and at the same page retrieve the data from the uploaded excel file.

the problem is when i click the upload button, i got this error:

org.apache.jasper.JasperException: Unable to get connection, DataSource invalid: "java.sql.SQLException: [Microsoft][ODBC Excel Driver] The Microsoft Jet database engine cannot open the file '(unknown)'. It is already opened exclusively by another user, or you need permission to view its data."

but after i refresh the page, it display the page that is expected (which display the data retrieve from uploaded excel file)

I'm sure that I didn't open the file via some other application such as Microsoft Excel when I run the code.

<!-- Connect to ms excel -->
<sql:setDataSource var="mp"
url="jdbcdbc:mp-list" />

<sql:query var="rs" dataSource="${mp}">

<form action="upload.jsp" enctype="multipart/form-data" method="post">
<b>File : </b><input type=file size=20 name="fname"/>
<INPUT TYPE="Submit" NAME="Submit" VALUE="Upload">

<form name="planForm" action="updateDeviceInfo.jsp" method="post" onsubmit="return validate_form(this)">
<b><font color="#0000CC">Plan ID: </font></b>
<input name="planId" type="text" size="8" value="${param.planId}" /></p>

<td><b>Device <b></td>

<c:forEach var="Row" items="${rs.rows}">
<td><input name="partId" type="text" size="25" value="${Row.PartId}" /></td>
<td><input name="qty" type="text" size="12" value="${Row.Qty}" /></td>

<input type="reset" name="reset" value="Clear">
<input type="submit" name="submit" value=" Submit "/>


<%@ page import="java.util.*,*,


boolean isMultipart = ServletFileUpload.isMultipartContent(request);

String fileName = "";

DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = upload.parseRequest(request);
Iterator iter = items.iterator();

String name = "";
String value = "";
InputStream stream = null;

//check any field to pass in

while (iter.hasNext())
FileItem item = (FileItem);
name = item.getFieldName();//field name
value = item.getString();//field value

if (!item.isFormField()) {

name = item.getName();

if(name != null ){

//Upload file --start
fileName = new File(item.getName()).getName();
//Get upload diectory from xml
String uploadDirectoty="C://Program Files//Apache Software Foundation//Tomcat 5.5//webapps//QFN_Planning//uploadFiles//";

File file = new File(uploadDirectoty + fileName);

File dir = new File(uploadDirectoty);
if (!dir.exists())
new File(uploadDirectoty).mkdirs();

FileOutputStream fos = new FileOutputStream(file);
stream = item.getInputStream();

int c;
while(( c = != -1 )
fos.write( c );




<c:redirect url="Form.jsp"/>

Above is my coding..

Please point out the problem and suggest solution..
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

Originally posted by Chen Nee Lim:
Please point out the problem and suggest solution..

There should be no such connection code in a JSP. Factor the code out to a Java class that is more easily debugged. Your JSP should have no Java code in it, especially as you are already using the JSTL.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Unable to get connection
It's not a secret anymore!