SOS !! 关于 jspSmartUpload 上传文件到数据库的问题,说明内详!

liqweijack 2003-10-10 01:45:49
环境配置:
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"); 一切正常

请大家帮忙想想问题出在哪??? 小弟急用!!!
...全文
43 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lfecnu 2003-10-30
  • 打赏
  • 举报
回复
关注!
我图片上传到Oracle业余到了问题。但除了图片其他字段能够正常更新。你把mySmartUpload.getFiles().getFile(0).fileToField(rs,"file"); 注释掉看看。
lfecnu 2003-10-28
  • 打赏
  • 举报
回复
up!

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧