日期:2014-05-16  浏览次数:20400 次

oracle 数据库中clob字段的修改

 //String sqlsel2 = "select jsonbody from db_ps_listcatalog where" +
//			"  listtype ='sh11' for update";
//    	String col="jsonbody";

public  boolean updateClob(String sql,String col,String buf){
		boolean flag=false;
		  Statement stem=null;
		  Connection conn=null;
		  ResultSet rs=null;
		  Writer wr = null;
		  try{ 
			  	conn= dp.getConnection();
		         conn.setAutoCommit(false); 
		         stem=conn.createStatement();
		         rs = stem.executeQuery(sql); 
		         if (rs.next()) { 
		        	 CLOB clob = (CLOB) rs.getClob(col); 
		        	 java.lang.reflect.Method methodToInvoke = clob.getClass().getMethod(
		                        "getCharacterOutputStream", (Class[]) null);
		        	 wr = (Writer) methodToInvoke.invoke(clob, (Object[]) null);
		        	 BufferedWriter bw = new BufferedWriter(wr);
		        	 bw.write(buf);
		        	 bw.flush();
		        	 bw.close();
		             conn.commit(); 
		             conn.close(); 
		         } 
		         flag=true;
		} catch (Exception ex){ 
			 try {
				 conn.rollback();
			 } catch (SQLException e) {
				 e.printStackTrace();
			 }
		}
		return flag;
	}