怎么没人理我?自己up!刚才我在WEBLOGIC7.X中用CLOB倒是可以了,但JBOSS3.X中还是不行,是JBOSS不支持还是我什么地方设置的不对?(我已经把JBOSS中对ORACLE的数据类型映射改成CLOB的了,但还是不对。)
顺便说一下,我原来有个content字段是用varchar2(4000)的,但发觉如果这个字段内容的长度大于一定值但还没有超过4000时会在Entity Bean的setContent()方法处出错(不论是JBOSS或WEBLOGIC中,不知是不是有什么地方的配置有问题),所以才想用CLOB来替换原来的varchar2类型。
而且对CLOB类型的用法还不是很清楚,求各位大哥大姐救我!

解决方案 »

  1.   

    oracle的jdbc driver对clob和blob的存取存在问题,解决办法是安装oci driver,当然还要装oracle client,并配置本地net service用它去连接远程数据库!我刚解决了不能存取blob类型的问题(也不是说不能存取,只是如果数据太大的话就存不进去了)!至于长字符串存取的问题我也解决了!可看此链接:http://expert.csdn.net/Expert/TopicView3.asp?id=1772117
      

  2.   

    public String getClobValue(Clob c){
        StringBuffer sb = new StringBuffer(1024);
        Reader instream = null;
        try{
            instream = c.getCharacterStream();
            char[] buffer = new char[(int)c.length()];
            int length = 0;
            while ((length = instream.read(buffer)) != -1){
                sb.append(buffer);
            }
        }
        catch(Exception ex){
           ex.printStackTrace();
        }
        finally{
           try{
              if(instream != null) instream.close();
           }
           catch(Exception dx){
              instream = null;
           }
           return sb.toString();
        }
    }
      

  3.   

    BLOB is a reference to data in a database. This example demonstrates how to retrieves bytes from a BLOB. 
        try {
            Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT col_blob FROM mysql_all_table");
        
            if (rs.next()) {
                // Get the BLOB from the result set
                Blob blob = rs.getBlob("col_blob");
        
                // Get the number bytes in the BLOB
                long blobLength = blob.length();
        
                // Get bytes from the BLOB in a byte array
                int pos = 1;   // position is 1-based
                int len = 10;
                byte[] bytes = blob.getBytes(pos, len);
        
                // Get bytes from the BLOB using a stream
                InputStream is = blob.getBinaryStream();
                int b = is.read();
            }
        } catch (IOException e) {
        } catch (SQLException e) {
        }
    or description=news1.getSubString((long)1,(int)news1.length());
      

  4.   

    关于往Oracle的clob字段中写数据的问题
    以下是部分代码:
    sql="insert into drug (title,keyword,category,picture,pic_memo,content,station,grid,inputdate) values('"+title+"','"+keyword+"','"+arry+"','"+picture+"','"+pic_memo+"',empty_clob(),'"+station+"','"+grid+"',sysdate+"+hours+")";

        try
    {           conn=ConnectionManagerFactory.getConnectionManager().getConnection("jdbc:oracle:thin:@localhost:1521:oracle1");
             conn.setAutoCommit(false);
        stmt=conn.createStatement();
    stmt.executeUpdate(sql);
    //取出最大的ID,既刚刚插入记录的ID 
                sql="select max(id) as maxid from drug";  
    rs=stmt.executeQuery(sql);
    while (rs.next())
    {
    maxid=rs.getString("maxid");
    }
    rs.close();
    //将CLOB字段类型的数据插入到数据库中
    sql="select content from drug where id='"+maxid+"' for update ";
    rs=stmt.executeQuery(sql);
    oracle.sql.CLOB clobtt=null;
    while(rs.next())

               clobtt = (oracle.sql.CLOB)rs.getClob(1); 
    }
    java.io.Writer wr = clobtt.getCharacterOutputStream();
    wr.write(content);
    wr.flush();
    wr.close();
    rs.close();
    conn.commit();