给你看一个我们以前做的,更新数据库的:
Connection con = DBManager.getConnection(); con.setAutoCommit(false); try {
Statement stmt = con.createStatement(); /* 清空原BLOB对象 */
String resetBlob =
"UPDATE "
+ tableName
+ " SET "
+ columnName
+ "=EMPTY_BLOB() WHERE "
+ whereClause; stmt.executeUpdate(resetBlob); /* 查询此BLOB对象并锁定 */
String selectBlobForUpdate =
"select "
+ columnName
+ " from "
+ tableName
+ " where "
+ whereClause
+ " for update"; ResultSet rs = stmt.executeQuery(selectBlobForUpdate); while (rs.next()) {
/* 取出此BLOB对象 */
oracle.sql.BLOB blob =
(oracle.sql.BLOB) rs.getBlob(
columnName); /* 向BLOB对象中写入数据 */
BufferedOutputStream out =
new BufferedOutputStream(
blob.getBinaryOutputStream());
BufferedInputStream in =
new BufferedInputStream(
readFile(fileName));
//blob.putBytes(1,b);
int c; while ((c = in.read()) != -1) { out.write(c);
}
in.close();
out.close(); }
/* 正式提交 */
con.commit();
rs.close();
stmt.close();
} catch (Exception ex) {
/* 出错回滚 */
con.rollback();
throw ex;
}
con.setAutoCommit(true); DBManager.closeConnection(); }

解决方案 »

  1.   

    第一步清空和第二步的for update很重要!
      

  2.   

    可我这段代码一直没问题啊
    直到改成WEBLOGIC自己的连接池就不行
     Clob clob = (Clob)rs.getClob(1);
    clobtt = (CLOB) clob;clobtt = (CLOB)clob这一行过不了
      

  3.   

    public boolean AddTemplate() throws Exception,ClassNotFoundException{
    boolean isOk = false;
    ResultSet rs = null;
    Connection conn = null;
    PreparedStatement pstmt = null;
    try {
    conn = DBConnect.getConnection();
    conn.setAutoCommit(false);
    pstmt = conn.prepareStatement("insert into N_TEMPLATE(template_id,name,filename,type,memo,content)"+
    "values(?,?,?,?,?,empty_clob())");
    pstmt.setInt(1,getTemplateId());
    pstmt.setString(2,getName());
    pstmt.setString(3,getFileName());
    pstmt.setString(4,getType());
    pstmt.setString(5,getMemo());
    pstmt.executeUpdate();



    //将CLOB字段类型的数据插入到数据库中
    pstmt = conn.prepareStatement("select content from N_TEMPLATE where template_id='" +
                            getTemplateId() + "' for update ");

    rs = pstmt.executeQuery();
    oracle.sql.CLOB clobtt = null;
    if (rs.next()) {
    clobtt =  (oracle.sql.CLOB) rs.getClob(1); java.io.Writer wr = clobtt.getCharacterOutputStream();
    wr.write(getContent());
    wr.flush();
    wr.close();
    } conn.commit();
    conn.setAutoCommit(true);

    isOk = true;

    } catch (Exception e) {
    // TODO 自动生成 catch 块
    conn.rollback();
    e.printStackTrace();
    }finally{
    try {
    if (rs != null) {
    rs.close();
    }
    if (pstmt != null) {
    pstmt.close();
    pstmt = null;
    }
    if (conn != null) {
    try {
    DBConnect.closeConnection(conn);
    } catch (Exception e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    }
    } catch (SQLException ex) {System.out.println("SQLException: "+ex);}  
    } return isOk;

    }这是我最初的代码,一直在用都没问题
      

  4.   

    1)导入weblogic的类文件,该文件在weblogic安装目录下就可以找到,weblogic.jar
       2)将以上语句改为weblogic.jdbc.vendor.oracle.OracleThinClob = null;
    if (rs.next()) {
    clobtt =  (OracleThinClob) rs.getClob
      

  5.   

    1)导入weblogic的类文件,该文件在weblogic安装目录下就可以找到,weblogic.jar
    2)将以上语句改为weblogic.jdbc.vendor.oracle.OracleThinClob = null;
    if (rs.next()) {
    clobtt = (OracleThinClob) rs.getClob