数据是从jsp页面传过来的大文本,本来在oracle 中定义了varchar2() ,但是只能存储4000字符数据,如果文章大于4000的话,存到数据库就会出现错误,所以我用clob来保存文本.但是数据存储后发现是乱码.请问怎样解决?

解决方案 »

  1.   

    写数据:
    String strContent="";
    ...
    if (result.next()) {
        //Creating the Role
        CLOB clobPaperContent = ((OracleResultSet)result).getCLOB("字段名称");
        int intReturn=clobPaperContent.putString(1,strContent);
        result.updateRow();
    读数据:
    if (result.next()) {
         //Creating the Role
         CLOB clobPaperCcontent =((OracleResultSet)result).getCLOB("字段名称");
         long longLen = clobPaperCcontent.length();
         strReturn =clobPaperCcontent.getSubString(1L, (int)longLen);
    }
      

  2.   

    对读出来的字符串进行转码试试如str=new String(str.getBytes("iso8859-1"),"GB2312");
      

  3.   

    多谢,已经解决  写数据时.我直接把String字符串写进clob字段的列里.
     String data= dataInfo.getDetail();
                   cs.se
    tString(1, newsInfo.getSubject());
            cs.setString(2, newsInfo.getAuthor());
            cs.setString(3, newsdetail);
     
    取数据:
      java.sql.Clob clob = null;            
    String rtn = null;
     while (rs.next())
            { 
                // 5 是clob类型字段
                clob =  rs.getClob(5);
                long longLen = clob.length();
                rtn = clob.getSubString(1L, (int) longLen);