图片上传至SQL数据库的问题?

Agla 2001-09-24 11:02:13
我用jspsmartupload上传图片到sql数据库,出现这样的错误
An error occurs : java.lang.NullPointerException 0 file(s) uploaded in the database.
我的sql数据库保存图片的字段类型是:image

<%@ 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;
String DriverString,JdbcURL,sql;

Connection conn=null;
java.sql.Statement stmt=null;
java.sql.ResultSet rs=null;

DriverString="sun.jdbc.odbc.JdbcOdbcDriver";
JdbcURL="jdbc:odbc:test";
Class.forName(DriverString);
conn=java.sql.DriverManager.getConnection(JdbcURL,"sa","");


// SQL Request
stmt = conn.createStatement();
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,"filel");

// 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();
conn.close();

%>

</BODY>
</HTML>





...全文
93 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wilddragon 2001-09-24
支持支持
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2001-09-24 11:02
社区公告
暂无公告