当前位置: 技术问答>java相关
使用jspsamrtupload上载文件到oracle出错?Help me!
来源: 互联网 发布时间:2015-05-26
本文导语: 把文件直接上传到oralce数据库的blob或clob总是出错, 我的代码是: String username = new String("oa"); String password = new String("oa"); String connectstring=new String("jdbc:oracle:thin:@dataserver:1521:richway"); ...
把文件直接上传到oralce数据库的blob或clob总是出错,
我的代码是:
String username = new String("oa");
String password = new String("oa");
String connectstring=new String("jdbc:oracle:thin:@dataserver:1521:richway");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(connectstring, username, password);
// SQL Request
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE ,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT filename,files FROM shifl_test where id=1");
//out.print(rs.getConcurrency());
// 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,"files");
// Update
rs.updateRow();
count++;
} catch(Exception e) {
out.println("An error occurs : " + e.toString());
}
}
}
错误提示是:An error occurs : java.sql.SQLException: 内部错误: Unable to construct a Datum from the specified input
0 file(s) uploaded in the database.
我的代码是:
String username = new String("oa");
String password = new String("oa");
String connectstring=new String("jdbc:oracle:thin:@dataserver:1521:richway");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(connectstring, username, password);
// SQL Request
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE ,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT filename,files FROM shifl_test where id=1");
//out.print(rs.getConcurrency());
// 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,"files");
// Update
rs.updateRow();
count++;
} catch(Exception e) {
out.println("An error occurs : " + e.toString());
}
}
}
错误提示是:An error occurs : java.sql.SQLException: 内部错误: Unable to construct a Datum from the specified input
0 file(s) uploaded in the database.
|
上传要与 更新数据库分开