SOS !! 关于 jspSmartUpload 上传文件到数据库的问题,说明内详!
环境配置:
Windows Server 2k sp3
IE 6.0
Sql Server 2k 企业版
Tomcat 4.1.27
jspSmartUpload(最近刚下载的)
问题:
在使用 jspSmartUpload 上传文件到数据库中是总是报错:
An error occurs : java.lang.NullPointerException 0 file(s) uploaded in the database.
但在使用 jspSmartUpload 的其它功能时一切正常;
我修改了 jspsmartupload.com 上提供的例子,代码如下:
<%@ page language="java" import="java.sql.*,com.jspsmart.upload.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<HTML>
<BODY BGCOLOR="white">
<H1>jspSmartUpload : Sample 4</H1>
<HR>
<%
// Variables
int count=0;
// Connect to the database
// ===================================== 修改驱动程序 !!
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
// ===================================== 修改系统Dsn !!
Connection con = DriverManager.getConnection("jdbc:odbc:myConnSql");
// SQL Request
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * FROM TFiles WHERE Id=1");
// if the resultset is not null
if (rs.next()){
// Initialization
mySmartUpload.initialize(pageContext);
// Upload
mySmartUpload.upload();
// upload file in the DB if this file is not missing
if (!mySmartUpload.getFiles().getFile(0).isMissing()){
try {
rs.updateString("fileName",mySmartUpload.getFiles().getFile(0).getFileName());
// Add the current file in the DB field
// mySmartUpload.getFiles().getFile(0).fileToField(rs,"file");
// Update
rs.updateRow();
count++;
} catch(Exception e) {
out.println("An error occurs : " + e.toString());
}
}
}
// Display the number of files uploaded
out.println(count + " file(s) uploaded in the database.");
rs.close();
stmt.close();
con.close();
%>
</BODY>
</HTML>
---------------------------------------------------
注: 单独访问数据库,打印 out.print("OK"); 一切正常
请大家帮忙想想问题出在哪??? 小弟急用!!!