POI读取EXCEL导入数据库(带源程序),导入到数据库的时候提示错误,请此方面的高手指点!在线等,急切!
我将EXCEL文件上传到服务器后(上传的路径是:C:/Tomcat5/webapps/ROOT/file/upload/),再将EXCEL导入数据库,导入的时候,TOMCAT提示下列错误:
java.io.IOException:Unable to read entir block;91 bytes read;expected 512 bytes
at org.apache.poi.poifs.storage.RawDataBlock. <init> <RawDataBlock.java:62>
at at org.apache.poi.poifs.storage.RawDataBlockList. <init> <RawDataBlockList.java:51>
at at org.apache.poi.poifs.filesystem.POIFSFileSystem. <init> <POIFSFileSystem.java:86>
at poi.POITest.readExceIToDB2(POITest.java:46)
at org.apache.jsp.ca_jsp._jspService(ca_jsp.java:51)
at org.apache.jasper.runtime.HttpJspBase.service(HttpjspBase.java:94)
at javax.serlet.http.HttpService(HttpSerlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
源程序如下:
POITest.java
-------------
<%@page contentType= "text/html;charset=GB2312 "%>
<%@ page import= "poi.POITest "%>
<%
String userid = session.getAttribute( "username ").toString();
boolean connectToDB = POITest.connectDB2();
if(connectToDB){
boolean tureOrfalse = POITest.readExcelToDB2(userid);
if (tureOrfalse==true){
out.println( "数据导入成功 ");
}else{
out.println( "数据导入失败 ");
}
}else{
out.println( "连接数据库失败! ");
}
%>
------------------
调用CLASS的JSP页面ca.jsp
<%@page contentType= "text/html;charset=GB2312 "%>
<%@ page import= "poi.POITest "%>
<%
String userid = session.getAttribute( "username ").toString();
boolean connectToDB = POITest.connectDB2();
if(connectToDB){
boolean tureOrfalse = POITest.readExcelToDB2(userid);
if (tureOrfalse==true){
out.println( "数据导入成功 ");
}else{
out.println( "数据导入失败 ");
}
}else{
out.println( "连接数据库失败! ");
}
%>
---------------------------------------------------
请高手指点!我个人觉得是不是由于上传的时候使用了java.io,读取excel的时候也需要java.io,两者冲突的原因?目前不得其解,请指点!非常感谢您的帮忙!
------解决方案--------------------POITest.java:46行是哪?
------解决方案--------------------把地址打印出来看看,然后用win路径访问试下