是的上传到Oracle 9i 9.2.0 数据库!
解决方案 »
- 很是烦:Microsoft Exchange MAPI support could not be enabled.
- jrockit求助
- 做过论坛的大大们进来看下吧
- 请问如何知道当前使用的JSP和Servlet的版本?
- javaweb加载文件时出的错误,大神求助
- 如何将已做好的jsp网站做成一个可进行安装的应用程序
- 关于java和dll,lib的问题,不知所措。
- PrintWriter out = new PrintWriter(new GZIPOutputStream(out1),false);不理解是什么意思。
- 如何去掉IE下拉框中某个记录?不是全部去掉
- 谁能推荐一本JSP的入门书籍?100分相送
- 求救:如何取得IE地址栏中的地址!up 都有分,谢谢!
- jsp中如何把值放入session中
先写个小程序看对数据库操作是否正常。
问一下,这个问题是第一次调用这个JSP就出错呢,还是调用若干次后再报错的?
你用的thin协议类的驱动,对每次读写的数据量有限制,好像是不能超过4k.所以,换个XA协议的驱动,或者用客户端。或者多次读写。
我给你个上传到oracle数据库的例子,
利用该组件,不过我把该组件给改过了!
<%@ page language="java" import="java.sql.*,java.net.*,java.lang.String,com.jspsmart.upload.*"%>
<%@ page contentType="text/html; charset=GB2312" %>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" /><HTML>
<BODY BGCOLOR="white"><H1>jspSmartUpload : Sample 4</H1>
<HR>
<%!
//---------//转换为汉字编码
public String gbStr(String str){
try {
str=new String((str+"").getBytes(),"ISO8859_1");
} catch (java.io.UnsupportedEncodingException e) { str="UnsupportedEncodingException"; }
return str;
}
int i = 0;
%>
<% // Variables
int count=0;
i++;
// Connect to the database
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.0.13:1521:milin";
//orcl为你的数据库的SID
String user="peroffice";
String password="peroffice";
Connection conn= DriverManager.getConnection(url,user,password);
// SQL Request
//Statement stmt = objConn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);
//ResultSet rs = stmt.executeQuery("SELECT * FROM OPENFILE 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 {
String strFileName = mySmartUpload.getFiles().getFile(0).getFileName();
mySmartUpload.save("upload");
String strPath = request.getRealPath("/upload/") + "\\" + strFileName;
//strPath = "E:\\WebSite\\ArchiveManagement\\upload\\复件sample.zip";
System.out.println(strPath);
//strPath = encodeRedirectURL("E:\\WebSite\\ArchiveManagement\\upload\\精华ASP代码.doc");
//strPath = "E:\\WebSite\\ArchiveManagement\\upload\\" + URLEncoder.encode("精华ASP代码.doc","UTF-8");
java.io.File file = new java.io.File(strPath);
//java.io.FileInputStream fis = new java.io.FileInputStream(file);
System.out.println("FilePart is OK!");
//objConn.setAutoCommit(false);
/* 设定不自动提交 */
boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
try {
/* 插入一个空的BLOB对象 */
stmt.executeUpdate("INSERT INTO openfile VALUES (13,'"+strFileName+"',EMPTY_BLOB())");
/* 查询此BLOB对象并锁定 */
ResultSet rs = stmt.executeQuery("SELECT FILEC FROM openfile WHERE ID='13' FOR UPDATE");
while (rs.next()) {
/* 取出此BLOB对象 */
oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("FILEC");
/* 向BLOB对象中写入数据 */
java.io.BufferedOutputStream outFile = new java.io.BufferedOutputStream(blob.getBinaryOutputStream());
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.io.FileInputStream(file));
int c;
while ((c=in.read())!=-1) {
outFile.write(c);
}
in.close();
outFile.close();
}
/* 正式提交 */
conn.commit();
} catch (Exception ex) {
/* 出错回滚 */
conn.rollback();
throw ex;
}
/* 恢复原提交状态 */
conn.setAutoCommit(defaultCommit);
/*
PreparedStatement ps = objConn.prepareStatement("INSERT INTO openfile VALUES (?,?,?)"); ps.setInt(1,i);
ps.setString(2,file.getName());
System.out.println("Write FileName is OK!");
ps.setBinaryStream(3,fis,(int)file.length());
//ps.setBinaryStream(3,null,0);
System.out.println("Write File Content is OK!" + (int)file.length());
ps.executeUpdate();
System.out.println("Update is OK!");
ps.close();
System.out.println("ps.close()");
fis.close();
System.out.println("fis.close()");
//objConn.commit();
//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(SQLException 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();
System.out.println("Don't close the conn!");
try {
conn.close();
} catch (SQLException e) {
System.out.println(e);
}
System.out.println("THE END");
%>
</BODY>
</HTML>
<%@ page language="java" import="java.sql.*,java.net.*,java.lang.String,com.jspsmart.upload.*"%>
<%@ page contentType="text/html; charset=GB2312" %>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" /><HTML>
<BODY BGCOLOR="white"><H1>jspSmartUpload : Sample 4</H1>
<HR>
<%!
//---------//转换为汉字编码
public String gbStr(String str){
try {
str=new String((str+"").getBytes(),"ISO8859_1");
} catch (java.io.UnsupportedEncodingException e) { str="UnsupportedEncodingException"; }
return str;
}
int i = 0;
%>
<% // Variables
int count=0;
i++;
// Connect to the database
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.0.13:1521:milin";
//orcl为你的数据库的SID
String user="peroffice";
String password="peroffice";
Connection conn= DriverManager.getConnection(url,user,password);
// SQL Request
//Statement stmt = objConn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);
//ResultSet rs = stmt.executeQuery("SELECT * FROM OPENFILE 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 {
String strFileName = mySmartUpload.getFiles().getFile(0).getFileName();
mySmartUpload.save("upload");
String strPath = request.getRealPath("/upload/") + "\\" + strFileName;
//strPath = "E:\\WebSite\\ArchiveManagement\\upload\\复件sample.zip";
System.out.println(strPath);
//strPath = encodeRedirectURL("E:\\WebSite\\ArchiveManagement\\upload\\精华ASP代码.doc");
//strPath = "E:\\WebSite\\ArchiveManagement\\upload\\" + URLEncoder.encode("精华ASP代码.doc","UTF-8");
java.io.File file = new java.io.File(strPath);
//java.io.FileInputStream fis = new java.io.FileInputStream(file);
System.out.println("FilePart is OK!");
//objConn.setAutoCommit(false);
/* 设定不自动提交 */
boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
try {
/* 插入一个空的BLOB对象 */
stmt.executeUpdate("INSERT INTO openfile VALUES (13,'"+strFileName+"',EMPTY_BLOB())");
/* 查询此BLOB对象并锁定 */
ResultSet rs = stmt.executeQuery("SELECT FILEC FROM openfile WHERE ID='13' FOR UPDATE");
while (rs.next()) {
/* 取出此BLOB对象 */
oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("FILEC");
/* 向BLOB对象中写入数据 */
java.io.BufferedOutputStream outFile = new java.io.BufferedOutputStream(blob.getBinaryOutputStream());
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.io.FileInputStream(file));
int c;
while ((c=in.read())!=-1) {
outFile.write(c);
}
in.close();
outFile.close();
file.delete();
}
/* 正式提交 */
conn.commit();
} catch (Exception ex) {
/* 出错回滚 */
conn.rollback();
throw ex;
}
/* 恢复原提交状态 */
conn.setAutoCommit(defaultCommit);
/*
PreparedStatement ps = objConn.prepareStatement("INSERT INTO openfile VALUES (?,?,?)"); ps.setInt(1,i);
ps.setString(2,file.getName());
System.out.println("Write FileName is OK!");
ps.setBinaryStream(3,fis,(int)file.length());
//ps.setBinaryStream(3,null,0);
System.out.println("Write File Content is OK!" + (int)file.length());
ps.executeUpdate();
System.out.println("Update is OK!");
ps.close();
System.out.println("ps.close()");
fis.close();
System.out.println("fis.close()");
//objConn.commit();
//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(SQLException 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();
System.out.println("Don't close the conn!");
try {
conn.close();
} catch (SQLException e) {
System.out.println(e);
}
System.out.println("THE END");
%>
</BODY>
</HTML>