你说得没有错,是这个错误。
An error occurs : java.sql.SQLException: Invalid operation for read only resultset: updateString 0 file(s) uploaded in the database
可能是我们两个的oracle的driver版本太低了,可能不支持jdbc2.0。
只能换另外不种方式了。现在还在调试,不知道能不能成功。
An error occurs : java.sql.SQLException: Invalid operation for read only resultset: updateString 0 file(s) uploaded in the database
可能是我们两个的oracle的driver版本太低了,可能不支持jdbc2.0。
只能换另外不种方式了。现在还在调试,不知道能不能成功。
可能用Statement.executeUpdate()进行更新(JDBC1.0)。
2、可以下载oracle的新版本的driver应该是支持的。
3、下面的是用Statement.executeUpdate()进行更新。
4、也可修改SmartUpload中的File类进行更新。
*/
%><%@page contentType="text/html;charset=gb2312"%>
<%@ 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("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.4.105:1521:orame";
//orcl为你的数据库的SID
String user="username";
String password="12345";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); // 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 {
String sFileName = mySmartUpload.getFiles().getFile(0).getFileName() ;
mySmartUpload.save("/upload"); //web目录下一个子目录,用于保存文件的
out.println("aaaaaaaaa==="+sFileName) ;
String sPath = request.getRealPath("/upload/")+sFileName ;
out.println("path=="+sPath) ;
java.io.File file = new java.io.File(sPath); //从目录中读取文件再保存到数据库中。
java.io.FileInputStream fis = new java.io.FileInputStream(file);
PreparedStatement ps =
conn.prepareStatement("insert into tfile values (?,?,?)");
ps.setInt(1,3); //id号
ps.setString(2,file.getName()); //文件名
ps.setBinaryStream(3,fis,(int)file.length()); //文件,为Blob类型
ps.executeUpdate();
ps.close();
fis.close(); } catch(Exception e) {
out.println("An error occurs : " + e.toString());
}
} stmt.close();
conn.close();%>
</BODY></HTML>