我用java连接数据库 上传blob限制文件大小 上传后的blob文件 用update方法也无法修改
  PreparedStatement  fileu=conn.prepareStatement("update tblob set tblob= ? where tid='try106'");
每次修改后不管参数是什么都变成null用2.0的结果集 
(  stat=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);)
也不能修改 提示读取专用的结果集不能修改谁知道应该怎样接解决呀~

解决方案 »

  1.   

    stat=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);ResultSet rs=stat.executeQuery("SELECT * FROM TBLOB WHERE TID='try106'");
                
               System.out.println(rs.next());
                System.out.println(rs.getString (1));
               System.out.println(rs.getBlob(2).length());
               rs.updateBinaryStream(2,in,2000);
               rs.updateRow();<----异常
    以上是用2.0的代码
    以下是异常java.sql.SQLException: 读取专用的结果集不能修改 :updateBinaryStream
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
    at oracle.jdbc.driver.BaseResultSet.updateBinaryStream(BaseResultSet.java:279)
    at temp.main(temp.java:100)
      

  2.   

    我使用3参的reateStatement方法出现了这个异常
    java.lang.AbstractMethodError: oracle.jdbc.driver.OracleConnection.createStatement(III)Ljava/sql/Statement;
    at temp.main(temp.java:29)
    Exception in thread "main"
      

  3.   

    import oracle.sql.*;//for Oracle extensions to JDBC
    import oracle.jdbc.*;
    import oracle.jdbc.pool.*;
    String strSql = "select content from text_content where id = ? for update" ; 
    ps = _conn.prepareStatement(strSql);
    ps.setString(1,strID) ;
    rset = ps.executeQuery();
    while (rset.next())
    {
        CLOB web = ((OracleResultSet)rset).getCLOB(1) ;
        Writer w = web.getCharacterOutputStream() ;
        
        w.write("ssssssssssssssss") ;
        w.flush() ;
        w.close() ;
    }
    rset.close() ;
    ps.close() ;clob 和 blob应该是一样的!
      

  4.   

    用java作,好像不是很难吧,按照我给的例子就行,呵呵,我原来用pro*C和pl/sql作的比较麻烦哪!
      

  5.   

    关键要看你用的是什么应用服务器.以及你用的是class.forname方式还是connection pool方式了.
    在各种情况下对blob进行处理是有区别的.
      

  6.   

    不行呀 在 rset = ps.executeQuery(); 这里进入了阻塞 无异常
      

  7.   

    Class.forName("oracle.jdbc.driver.OracleDriver");
                String url="jdbc:oracle:thin:@192.168.1.6:1521:mrdwh"; 
                String user="system"; 
                String password="manager"; 
                conn= DriverManager.getConnection(url,user,password);
                stat=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
               
    这是代码 应该没有错误的吧 但是就是不能够修改结果集
      

  8.   

    private OracleConnectionPoolDataSource ocpds ;
        private PooledConnection pc ;
        public CreateConnectPool()
        {
            try 
            {
                // Create a OracleConnectionPoolDataSource instance
                ocpds = new OracleConnectionPoolDataSource();
                // Set connection parameters
                ocpds.setURL("jdbc:oracle:oci8:@mrdwh");
                
                //ocpds.setDriverType("oci8");
                //ocpds.setServerName("mrdwh");
                //ocpds.setNetworkProtocol("tcp");
                //ocpds.setDatabaseName("mrdwh");
                //ocpds.setPortNumber(1521);
                
                ocpds.setUser("system");
                ocpds.setPassword("manager");
                // Create a pooled connection
                pc = ocpds.getPooledConnection();
            }
            catch( Exception e ) 
            {
                System.out.println(e.getMessage());
                e.printStackTrace();
            }    
        }
        
        private Connection getConnection()
        {
            try 
            {
                // Get a Logical connection
                return pc.getConnection();
            }
            catch( Exception e ) 
            {
                System.out.println(e.getMessage());
                e.printStackTrace();
                return null ;
            }    
        }
        
        public void Connect() 
        {
            conn = getConnection() ;
            if(conn!=null)
            {
                System.out.println("Connection successful.");
            }
        }    public void Disconnect() 
        {
            try 
            {
                conn.close();
                conn = null ;
                System.out.println("DisConnection successful.");
                
            }
            catch( Exception e ) 
            {
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        }
      

  9.   

    如果 select 语句加上for update 就会造成阻塞 不加的话别 结果集不能够 修改
    而且加上也不知道 能不能改... 大虾们 有没有知道的呀
      

  10.   

    搂主用我给你的连接方式试试吧,这是我们系统的部分代码,没问题的Oracle9i的
      

  11.   

    public java.io.ByteArrayOutputStream readFileFromDB(int index, String ifwhere) {    InputStream is = null;
        int bytesread = 0;
        byte[] butter = new byte[8 * 1024];
        java.io.ByteArrayOutputStream bos = null;
        String sql = "";
        java.sql.Blob blob = null;
        sql = sqlblob[index] + ifwhere;
    //    System.out.println(sql);
    //
    //    System.out.println(sql);
        try {
          //Initialization ByteArrayOutputStream
          bos = new java.io.ByteArrayOutputStream();
          //Get Connection
          con = new DBconn().getConnection();      pst = con.prepareStatement(sql);
          rs = pst.executeQuery();
          int size = 0;
          while (rs.next()) {
            //Get Blob
            blob = rs.getBlob(1);
            if (blob != null && blob.length() != 0) {
              is = blob.getBinaryStream();
              while ( ( (bytesread = is.read()) != -1)) {
                bos.write(bytesread);
              }        }
          }    }
        catch (Exception e) {
          System.out.println(e.toString());
        }
        finally {
          try {
            if (rs != null)
              rs.close();
            if (pst != null)
              pst.close();
            if (con != null)
              con.close();      }
          catch (Exception e) {
            System.out.println("数据库连接错误:" + e.toString());
          }
        }
        return bos;
      }
      

  12.   

    liuyi8903(甜脆夹心) 那个...我想要做的 是 修改  不是下载..... hoho
      

  13.   

    hqskoala  PooledConnection 我没找到 这个类
      

  14.   

    public void writeDBFromFile(String pathname) {
        myFile = new File(pathname);
        try {
          //将文件转化为文件流
          java.io.FileInputStream fis = new FileInputStream(myFile);
          //得到一个数据库连接
          con = new DBconn().getConnection();
          pst = con.prepareStatement("update test set mblob=? where id=2");
          //pst.setInt(1,2);
          byte bb[];
          String sql = "ab";
          bb = sql.getBytes();
          pst.setBinaryStream(1, new java.io.ByteArrayInputStream(bb), bb.length);
          //pst.setBinaryStream(1,fis,(int)myFile.length());
          pst.executeUpdate();
        }
        catch (Exception e) {
          System.out.println(e.toString());
        }
        finally {
          try {
            if (rs != null)
              rs.close();
            if (pst != null)
              pst.close();
            if (con != null)
              con.close();      }
          catch (Exception e) {
            System.out.println(e.toString());
          }
        }
      }
      

  15.   

    我本来是想上传大blob 但是每次 上传流都不能超5k所以我想 先上传一部分产然后在追加 后面 的不过 为什么 修改的是 覆盖 原来的内容呀 ....
      

  16.   

    import oracle.jdbc.*;
    import oracle.sql.*;//for Oracle extensions to JDBC
    import oracle.jdbc.pool.*;
      

  17.   

    import java.sql.*;
    import java.io.*;
    import oracle.jdbc.*;
    import oracle.jdbc.pool.*;
    import oracle.jdbc2.*;
    import oracle.sql.*;我都用了
      

  18.   

    不是我限制的呀  超过5k他会提示TNS end of channgel (好像是这样的一个异常)
      

  19.   

    你for  update了吗?如果是的话很可能是你没有commit or rollback
      

  20.   

    for  update必须要用commit or rollback吗?
    我没用批处理但是用for update的时候 就会阻塞...
      

  21.   


    java.sql.SQLException: 无法操作: streams type cannot be used in batching
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
    at oracle.jdbc.driver.OraclePreparedStatement.addBatch(OraclePreparedStatement.java:3262)
    at temp.main(temp.java:52)
      

  22.   

    public class  temp
    {
        public static void main(String[] args) 
        {   Connection conn;
             Statement stat;
                FileOutputStream out;
            try {
                Class.forName("oracle.jdbc.driver.OracleDriver");
                String url="jdbc:oracle:thin:@192.168.1.6:1521:mrdwh"; 
                String user="system"; 
                String password="manager"; 
                conn= DriverManager.getConnection(url,user,password);
                stat=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
                byte[] b=null;
                byte[] bt=null;
                File f= new File("d:/log.jpg");
                System.out.println(f.length());
                FileInputStream in= new FileInputStream (f);
                b= new byte[(int)f.length()];
                in.read(b);
                in.close();
                in= new FileInputStream (f); 
                conn.setAutoCommit(false);                                                                               
     PreparedStatement pst = conn.prepareStatement("update tblob set tblob=? where tid='try001' ");

      byte bb[];
      String sql = "ab";
      bb = sql.getBytes();

      pst.setBinaryStream(1,in,b.length);
    pst.addBatch();
    pst.executeBatch();
    conn.commit();
    conn.setAutoCommit(true);
         
           }
            catch (Exception e){
                e.printStackTrace();         
            }
            System.out.println("over");
        }
        上面的代码有错误吗?