求救:关于jdbc 存取 oracle clob 的问题?
p731 2005-11-16 04:41:59 快疯了,在网上找了很多相关资料参考。结果还是搞不定。代码在下面。其中的字符串s的长度是几个字母时,还是可以存储的,只不过是乱码。当长度加到数十个时,执行时,在commit的地方就停止响应了。(weblogic 8 oracle 817)
//========================================
<%@ page contentType="text/html; charset=gb18030" language="java" %>
<%@ page import="javax.sql.*,java.sql.*,oracle.jdbc.driver.*"%>
<%
java.sql.Connection sqlCon = null;
boolean f = false;
Statement st = null;
OraclePreparedStatement pstmt = null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
sqlCon = DriverManager.getConnection("jdbc:oracle:thin:@10.0.0.113:1521:ora8i","zbxt","zbxt");
f = sqlCon.getAutoCommit();
sqlCon.setAutoCommit(false);
st = sqlCon.createStatement();
oracle.sql.CLOB myClob = null;
st.execute("SELECT nr from tt where id = '1' for update");
OracleResultSet rs = (OracleResultSet)st.getResultSet();
while (rs.next()) {
myClob = (oracle.sql.CLOB)rs.getClob("nr");
}
String s = "fffdffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdddd";
System.out.println("hhhhhhhhhhhhhhhhhhhh");
myClob.putString(1,s);
System.out.println("dddddddddddddddddddddddd");
pstmt = (OraclePreparedStatement)sqlCon.prepareStatement("update tt set nr=? where id='1'");
pstmt.setClob(1,myClob);
pstmt.executeUpdate();
/*java.io.Writer wr = myClob.getCharacterOutputStream();
BufferedWriter bwr = new BufferedWriter(wr);
bwr.write(s,0,s.length());
bwr.flush();
bwr.close();*/
sqlCon.commit();
System.out.println("ffffffffffffffffffffffffffffffff");
} catch(Exception e) {
sqlCon.rollback();
System.out.println(e.toString());
} finally {
try {
if(st != null) st.close();
if(pstmt != null) pstmt.close();
if(pstmt != null) st.close();
if(sqlCon != null) {
sqlCon.setAutoCommit(f);
sqlCon.close();
}
} catch(Exception e) {System.out.println(e.toString());}
}
%>
//=======================================