小弟最近做项目遇到了需要存取clob类型的字段,希望各位大虾能给一些这方面的资料或者代码例子,小弟是新手,所以最好详细点,谢谢了

解决方案 »

  1.   

    public void saveA(A a) {
    Session session = getSession();
    session.beginTransaction();
    SerializableClob clob = (SerializableClob) a.getDescriptionClob();
    java.sql.Clob wrapClob = clob.getWrappedClob();
    oracle.sql.CLOB tmpClob = (oracle.sql.CLOB) wrapClob;
    tmpClob.putString(1, a.getDescription());
    session.saveOrUpdate(a);
    session.evict(a);
    }
    public class A{
    private Clob descriptionClob;
    private String description;
            
          ....setter ...getter...}
      

  2.   

    Clob clob = ResultSet.getClob("Clob"); // 读取Clob字段
    public static String getClobString(Clob clob) {
    try {
    Reader reader = clob.getCharacterStream();
    if (reader == null) {
    return "";
    }
    StringBuffer sb = new StringBuffer();
    char[] charbuf = new char[4096];
    for (int i = reader.read(charbuf); i > 0; i = reader.read(charbuf)) {
    sb.append(charbuf, 0, i);
    }
    return sb.toString();
    } catch (Exception e) {
    return "";
    }
    }