Oracle数据库中STRING类型字段不能超过4K,超过了应该使用CLOB,
我没有仔细看你的异常信息(实在太乱了,SWEAT),如果你是使用STRING类型,那么请
改为CLOB存储超过4K字节的数据。

解决方案 »

  1.   

    忘了说了,字段类型是Blob,(里面放的文档,doc,pdf等)
      

  2.   

    如果是Oracle中字段类型为varchar或varchar2(具体二者有什么区别,我还不太知道),那么最大长度是不能大于4k的,也即4XXX(4千多,具体忘了)。如果你要上传超过4K,那就用Blob吧,它可放任何二进制数据。如果是文本,也可用Clob,至于用法,CSDN上就有很多。
      

  3.   

    byte[] buffer....//文件内容
    int len=buffer.length;
    ByteArrayInputStream in=new ByteArrayInputStream(buffer);
    pstmt = conn.prepareStatement("insert into ITEM_PIC(ITEM_ID,PIC_NUM,PIC)values(?,?,?)");
    pstmt.setString(1, item_id);
    pstmt.setInt(2,pic_num);
    pstmt.setBinaryStream(3, in, len);
    pstmt.execute();
    这样操作的,有错误么???
      

  4.   

    你这么写能不能成功我不知道,我现在也没法子试验。
    不过我们用过的成果的法子是先用 empty_blob() 将lob字段清空,然后select取得lob字段对应的 BinaryStream,然后对这个流进行操作。
    这种做法是从Oracle的官方文档里面弄下来的,好像是因为Weblogic 的DataSource 和Oracle自己的sql API 的问题,不管怎么样,反正是成功的方法吧。
    下面是我们用过的代码,希望对你有帮助:  public void writeBlob(String tableName, String blobColumnName, String primaryKeyName, int id, byte[] blobContent) {
        try {
          ServiceLocator sl = new ServiceLocator();
          DataSource ds = sl.getDataSource(JNDINames.GENERAL_DATASOURCE);
          Connection con = ds.getConnection();
          Statement st = con.createStatement();
          st.setQueryTimeout(120);
          String updateSql =
              "update " + tableName.trim() +
              " set " + blobColumnName + " = empty_blob()" +
              " where " + primaryKeyName.trim() + " = " + id;
          String querySql =
              "select " + blobColumnName.trim() +
              " from " + tableName.trim() +
              " where " + primaryKeyName.trim() + " = " + id;
          //System.err.println( "update sql = " + updateSql);
          //System.err.println( " query sql = " + querySql);
          st.executeUpdate( updateSql);
          ResultSet rs = st.executeQuery( querySql);
          if ( rs.next()){
            OracleThinBlob blob = (OracleThinBlob)rs.getBlob( blobColumnName.trim());
            OutputStream os = blob.getBinaryOutputStream();        ByteArrayInputStream byteStream = new ByteArrayInputStream( blobContent);        byte[] line = new byte[ blob.getBufferSize()];
            //确保存入的字节总数不变
            int readTimes = blobContent.length / blob.getBufferSize();
            int lastByteCount = blobContent.length % blob.getBufferSize();
            for ( int i = 1; i <= readTimes+1; i++){
              byteStream.read( line);
              if ( i <= readTimes ){
                os.write( line, 0, line.length);
              }else{
                os.write( line, 0, lastByteCount);
              }
            }
            os.flush();
            byteStream.close();
            os.close();
          }else{
            Debug.debug("Lob 写操作: session bean 中查询得到的ResultSet没有纪录。");
            throw new EJBException();
          }
        }
        catch (IOException ex) {
          Debug.debug(ex);
          throw new EJBException(ex);
        }catch (SQLException ex) {
          Debug.debug(ex);
          throw new EJBException(ex);
        }catch (ServiceLocatorException ex) {
          Debug.debug(ex);
          throw new EJBException(ex);
        }
      }//这段代码有些地方有问题的,请不要见笑
      

  5.   

    // String url = "jdbc:oracle:thin:@localhost:1521:oradb";
    String url = "jdbc:oracle:oci8:@oradb";
    用下面的url(需要安装oracle的客户端)
      

  6.   

    我是受到启发了,看看这里啊
    http://www.csdn.net/develop/article/18/18987.shtm
    可惜我早没有看到这篇文档。