如何在JSP网站上实现把浏览器提交的execel 2003数据表导入sql server 2008中?
我想在JSP网站上实现把浏览器提交的execel 2003数据表导入到sql server 2008中,运行程序出现“[Microsoft][ODBC SQL Server Driver][SQL Server]链接服务器 "(null)" 的 OLE DB 访问接口 "microsoft.jet.oledb.4.0" 报错。提供程序未给出有关错误的任何信息。”,代码如下,哪位高手帮忙指点一下,不胜感激!<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*"%>
<jsp:useBean id="db" class="cn.DBcon"></jsp:useBean>
<jsp:useBean id="chStr" scope="page" class="cn.chStr"/>
<%
String path=application.getRealPath(".");
String dir=new File(path).getParent()+"\\excel";
String x1=dir+"\\szbm.xls";
x1=chStr.chStr(x1);
File f=new File(dir,"szbm.xls");
if(f.exists())
{
if(f.renameTo(f))
{
String s="select * from tb_szbm";
ResultSet r=db.getStmt().executeQuery(s);
if(r.next())
{
File f1=new File(dir,"szbm.xls");
if(f1.exists())
{
f1.delete();
}
%>
<script type="text/javascript">
alert("部门信息存在,不能导入信息");
window.location.href="rs_szbmlr.jsp";
</script>
<%
}
else
{
String sql="insert into tb_szbm select * from OPENROWSET('microsoft.jet.oledb.4.0','Excel 5.0; HDR=YES;DATABASE="+x1+"',szbm$)";
int rs=db.getStmt().executeUpdate(sql);
if(rs>0)
{
String a="select bmbh,bmmc from tb_szbm";
ResultSet b=db.getStmt().executeQuery(a);
for(int i=0;i<rs;i++)
{
String a1="select top 1 bmbh,bmmc from tb_szbm where bmbh not in (select zgbh from tb_zhgl ) ";
ResultSet b1=db.getStmt().executeQuery(a1);
String zgbh="";
String sfz="";
String zgxm="";
String mm="123456";
if(b1.next())
{
zgbh=b1.getString(1);
zgxm=b1.getString(2);
sfz=zgbh;
}
String a2="insert into tb_zhgl(zgbh,sfz,zgxm,mm,qx) values('"+zgbh+"','"+sfz+"','"+zgxm+"','"+mm+"','b')";
int b2=db.getStmt().executeUpdate(a2);
if(b2>0)
{
File f1=new File(dir,"szbm.xls");
if(f1.exists())
{
f1.delete();
}
%>
<script type="text/javascript">
alert("部门信息插入成功");
window.location.href="rs_szbmlr.jsp";
</script>
<%
}
}
}
else
{
File f1=new File(dir,"szbm.xls");
if(f1.exists())
{
f1.delete();
}
%>
<script type="text/javascript">
alert("部门信息导入失败");
history.back();
</script>
<%
}
}
}
else
{
File f1=new File(dir,"szbm.xls");
if(f1.exists())
{
f1.delete();
}
%>
<script type="text/javascript">
alert("文件导入失败,请查看您的文件是否关闭");
history.back();
</script>
<%
}
}
else
{
File f1=new File(dir,"szbm.xls");
if(f1.exists())
{
f1.delete();
}
%>
<script type="text/javascript">
alert("所选文件不存在");
history.back();
</script>
<%
}
%>
补充:Java , Web 开发