Results 1 to 1 of 1
Thread: Unable to get connection
- 09-24-2008, 02:33 AM #1
Member
- Join Date
- Aug 2008
- Posts
- 3
- Rep Power
- 0
Unable to get connection
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.
Form.jsp
<!-- Connect to ms excel -->
<sql:setDataSource var="mp"
driver="sun.jdbc.odbc.JdbcOdbcDriver"
url="jdbc:odbc:mp-list" />
<sql:query var="rs" dataSource="${mp}">
SELECT * FROM [MP$]
</sql:query>
<html>
<body>
<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>
<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>
<table>
<tr>
<td><b>Device <b></td>
<td><b>Qty</b></td>
</tr>
<c:forEach var="Row" items="${rs.rows}">
<tr>
<td><input name="partId" type="text" size="25" value="${Row.PartId}" /></td>
<td><input name="qty" type="text" size="12" value="${Row.Qty}" /></td>
</tr>
</c:forEach>
</table>
<input type="reset" name="reset" value="Clear">
<input type="submit" name="submit" value=" Submit "/>
</form>
</body>
</html>
upload.jsp
<%@ page import="java.util.*,
java.io.*,
java.sql.*,
org.apache.commons.fileupload.*,
org.apache.commons.fileupload.servlet.*,
org.apache.commons.fileupload.disk.*,
org.apache.commons.fileupload.util.*"
%>
<html>
<body>
<%
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if(isMultipart)
{
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) iter.next();
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 = stream.read()) != -1 )
{
fos.write( c );
}
stream.close();
}
}
}
}
%>
<c:redirect url="Form.jsp"/>
Above is my coding..
Please point out the problem and suggest solution..
Similar Threads
-
Unable to get connection, DataSource invalid:
By kwesiaryee in forum New To JavaReplies: 0Last Post: 09-17-2008, 01:36 PM -
Unable to Run Servlet
By basark in forum Java ServletReplies: 4Last Post: 07-11-2008, 08:08 AM -
JasperException: Unable to compile
By Aerinai in forum Java ServletReplies: 0Last Post: 06-17-2008, 06:16 PM -
Unable to get a XAConnection from the DataSource.
By Eric in forum Enterprise JavaBeans (EJB)Replies: 3Last Post: 05-16-2008, 11:17 AM -
Unable to compile
By gapper in forum New To JavaReplies: 2Last Post: 01-14-2008, 04:31 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks