怎样用jspsmartupload将一个文件存入数据库(sqlserver2000)

xiaoxion 2002-01-23 08:01:43
怎样用jspsmartupload将一个文件存入数据库(sqlserver2000),恳请想告,分数如是奉上
...全文
14 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
weidegong 2002-04-27
我也补个问题,如何将上传文件通过SQL语句的形式存入数据库哪?
Connection con=conPDM.getConn();
PreparedStatement pstmt=con.prepareStatement(strSQLAdd);
for(int i=0;i<mySmartUpload.getFiles().getCount();i++){
java.io.File file=mySmartUpload.getFiles().getFile(i);
FileInputStream fis = new FileInputStream(file);
pstmt.setBinaryStream(i+1,fis,file.getSize() );
}//end for(int i=0;...为pstmt设置参数完成
pstmt.executeUpdate();

这样不太对呀
回复
weidegong 2002-04-27
<%@ 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("org.gjt.mm.mysql.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql:///test");

// SQL Request
Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY ,ResultSet.CONCUR_UPDATABLE);
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>




回复
zhjx_10 2002-01-23
看看它的sample
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告