大概是你关于大对象的buffer size设置得太小。

解决方案 »

  1.   

    blob不能直接用户sql语句直接插入,否则只能插入2000个字符,的应用jdbc专门提供的类操作。
      

  2.   

    这是我们添加大文本文件的代码,你参考参考
     public void create(ClobForm clobForm,String tabName) throws CreateException {    PreparedStatement ps = null;
        PreparedStatement psUpt = null;
        ResultSet rs = null;
        long lClobId = clobForm.getClobId();
        
        //修要改*******222
        String sql = "insert into "+tabName+" (id,content) values (?,empty_clob())";
        String sqlClob = "select content from "+tabName+" where id=? for update";
        String sqlUpt = "update "+tabName+" set content=? where id=?";
        //*************222    try {      if (con.isClosed()) {
            throw new IllegalStateException("error.con.link");
          }      String sContent = clobForm.getClobContent();
          
          ps = con.prepareStatement(sql);
          
          //需要改*****333
          ps.setLong(1,lClobId);
          //***********333      if (ps.executeUpdate() != 1) {
            throw new CreateException("error.clob");
          }
          //添加大文本
          ps=null;
          ps = con.prepareStatement(sqlClob);
          ps.setLong(1,lClobId);
          rs = ps.executeQuery();
          if(rs.next())
          {
           oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob(1);
            clob.putString(1,sContent);
            psUpt = con.prepareStatement(sqlUpt);
            psUpt.setClob(1,clob);
            psUpt.setLong(2,lClobId);
            psUpt.executeUpdate();
          }
          
        } catch (SQLException e) {
          try {
           //改
            findByKey(lClobId,tabName);
            //****
          } catch (FinderException fe) {
            fe.printStackTrace();
            throw new RuntimeException("error.clob");
          }
          throw new DuplicateKeyException(
            "error.clob");
        } finally {
          try {
          
           if(rs != null)
           rs.close();
          
            if (ps != null)
              ps.close();
            
            if(psUpt != null)
             psUpt.close();
          } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException("error.clob");
          }
        }  }
      

  3.   

    我是这样储存的:
    、、、、、、、、、、、、、、、、
    、、、、、、、、、、、、、、、、、、、//-----------------------------------------------开始存储文件---------------------------------          oracle.jdbc.OracleResultSet ors = null; //**这里rs一定要用Oracle提供的
              oracle.jdbc.driver.OraclePreparedStatement opst = null; //**PreparedStatement用Oracle提供的          java.io.InputStream inStream = new java.io.FileInputStream(file);
              int fileSize = myFile.getSize();
              CZR = fileSize;          byte[] bytes = new byte[fileSize];          //**注意Oracle的 BLOB一定要用EMPTY_BLOB()初始化 (2)
               String mysql = "insert into GRWJLB(WJJBH,WJLBBH,WJMC,WJMS,WDNR,BZ,CZR,CZSJ,RY)values(?,?,?,?,EMPTY_BLOB(),?,?,?,?)";
               //String mysql ="insert into GRWJLB(WJJBH,WJLBBH,WJMC,WJMS,WDNR)values(?,?,?,?,EMPTY_BLOB())";
              opst = (oracle.jdbc.driver.OraclePreparedStatement)db1.conn.prepareStatement(mysql);
              opst.setInt(1, WJJBH);
              opst.setInt(2, WJLBBH);
              opst.setString(3, WJMC);
              opst.setString(4, WJMS);
              opst.setString(5, BZ);
              opst.setInt(6, CZR);
              opst.setDate(7, CZSJ);
              opst.setString(8, RY);
              opst.executeUpdate();
              opst.clearParameters();          //**插入其它数据后,定位BLOB字段 (3)          mysql="select WDNR from GRWJLB where WJJBH=? and WJLBBH=? for update";
              opst = (oracle.jdbc.driver.OraclePreparedStatement) db1.conn.
                  prepareStatement(mysql);
              opst.setInt(1, WJJBH);
              opst.setInt(2, WJLBBH);
              ors = (oracle.jdbc.OracleResultSet) opst.executeQuery();
              if (ors.next()) {
                //**得到BLOB字段 (4)
                 oracle.sql.BLOB blob = ors.getBLOB(1);
                 //**将字节数组写入BLOB字段 (5)
                inStream.read(bytes);
                int j = blob.putBytes(1, bytes);
                db1.conn.commit();
                ors.close();
                if (file != null) //删除文件
                  file.delete();
              }
              System.out.println("insert into ok");
      

  4.   

    最好不要用putbytes,因为你文件比较大
    试试这个:
    if (rs.next()) {
       oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("blob");
       BufferedOutputStream out = new BufferedOutputStream(blob.getBinaryOutputStream());
       BufferedInputStream in = new BufferedInputStream(file.getInputStream());
       int c;
       while ((c=in.read())!=-1) {
          out.write(c);
       }
       in.close();
       out.close();
    }