jdbc 存 oracle数据库CLOB 类型字段

 

public class LogDaoImpl extends HibernateDaoSupport implements LogDao {

 
 public void saveLogInfo(String serviceID, String msg,
   String xmlData,String flag) {
  
    Connection conn = null;
    PreparedStatement ps1=null;
    PreparedStatement ps2=null;
    ResultSet rs2=null;
   // 存储日志信息
   
   try {
   
    conn = newOracleConn.getOracleConn();
    conn.setAutoCommit(false);
    String sql1="insert into sky_service_log (servericetext,serverid,servicename,calltype,err_msg,op_date,flag,note) values (EMPTY_CLOB(),?,?,?,?,?,?,?)";
    
     ps1=conn.prepareStatement(sql1);
    
    ps1.setString(1,serviceID);
    ps1.setString(2," ");
    ps1.setString(3," ");
    ps1.setString(4," ");
    ps1.setTimestamp(5, new Timestamp(new Date().getTime()));
    ps1.setString(6,flag);
    ps1.setString(7," ");
    
    ps1.executeUpdate();
    ps1.close(); //第二步:取出该CLOB

    String sql2="select servericetext from sky_service_log for update";

      ps2=conn.prepareStatement(sql2);

     rs2=ps2.executeQuery();
    while (rs2.next()){
     oracle.sql.CLOB clob=(oracle.sql.CLOB)rs2.getClob(1);
     BufferedWriter out=new BufferedWriter(clob.getCharacterOutputStream());
     out.write(xmlData,0,xmlData.length());
     out.close();
     }
     conn.commit();

  } catch (Exception e) {
   e.printStackTrace();
  }finally {
   try {
    if( rs2!= null)
     rs2.close();
    if (ps2!= null)
     ps2.close();
    if( ps1 != null)
     ps1.close();
    if (conn != null)
     conn.close();
    
   } catch (SQLException e) {
    e.printStackTrace();
   }
  }
 }
 


}

你可能感兴趣的:(oracle,exception,数据库,jdbc,String,null)