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) {
    }

解决方案 »

  1.   

    Statement stmt = con.createStatement(
                                          ResultSet.TYPE_SCROLL_INSENSITIVE,
                                          ResultSet.CONCUR_UPDATABLE);
      

  2.   

    to ldianfeng(春城池):
    我是往里插入数据,不是读取数据。可以读出来,但视插不进去。
    to bruni(不如你):
    还是不行。这两个参数是什么意思啊?
      

  3.   

    conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=&password=");
    user= 用户为空也能访问mysql?  是不是这种方式下用户没有写入的权限,你将user=root试试。
      

  4.   

    to farmer0512(风总是朝我吹):
    对我用root登陆后添加的匿名用户,不用密码。
    可以自己设定访问权限
      

  5.   

    Help me!
    it is Urgent!
      

  6.   

    Statement stmt = con.createStatement(
                                          ResultSet.TYPE_SCROLL_INSENSITIVE,
                                          ResultSet.CONCUR_UPDATABLE);
           // rs will be scrollable, will not show changes made by others,
           // and will be updatableThen try Blob mapBLOB = (Blob)rsBlob.getBlob(1);
        OutputStream bout = mapBLOB.setBinaryStream(1);
        bout.write(outBytes,0,outBytes.length); //byte[]outBytes 在先前从文件中读出
        bout.close();rs.updateBlob(1, mapBLOB);
    rs.updateRow();
      

  7.   

    按照偶说的做肯定没问题,偶刚做完类似问题,我用的是oracle,CLOB或BLOB不允许直接插入操作,必须先插入空值,然后select出来,最后update,相信类似问题,你应该知道吧:(
    下边是我ORACLE例子:你修改一下,应该没问题:
    --------------------./........
    .........//连库的东东,
    title = new String(request.getParameter("title").getBytes("ISO8859-1"),"GB2312");
    news1  = new String(request.getParameter("news").getBytes("ISO8859-1"),"GB2312");
    tempclass =new String( request.getParameter("class").getBytes("ISO8859-1"),"GB2312");
        con.setAutoCommit(false);
        String sql = "INSERT INTO news (id,title,news,class) Values (se_dzzw.nextval,'"+title+"', empty_clob(), '"+tempclass+"')";
        PreparedStatement pstmt = con.prepareStatement(sql);   
        pstmt.executeQuery();   
        sql="select id from news where rownum<2 order by id desc";
        pstmt = con.prepareStatement(sql) ;
        ResultSet rs = pstmt.executeQuery(); 
        
        
        if(rs.next()){
        id = rs.getInt("id");   }        
        sql = "select news from news where id="+id+" ";
            pstmt = con.prepareStatement(sql) ;
        rs = pstmt.executeQuery(); 
     
         
    oracle.sql.CLOB clobtt = null; 
    if(rs.next()){ 
        clobtt = (oracle.sql.CLOB)rs.getClob("news"); 

    Writer wr = clobtt.getCharacterOutputStream(); 
    wr.write(news1); 
    wr.flush(); 
    wr.close(); 
    rs.close(); 
    con.commit(); 
        
    --------------------
      

  8.   

    太谢谢bruni(不如你)了,问题终于搞定了,搞得我晕头转向三天了!!
    不过按你写的执行程序是会报错:说是resultset必须是从以ResultSet.CONCUR_UPDATABLE为参数的,而且resultset必许是从唯一的表中选出来的,还有必须要包含主键。
    所以我是这样创建的:
    String sqlBlob = "select * from test where ID='***' for update";
    然后
    Blob mapBLOB = (Blob)rsBlob.getBlob("pic");
      

  9.   

    太谢谢bruni(不如你)了,问题终于搞定了,搞得我晕头转向三天了!!
    不过按你写的执行程序是会报错:说是resultset必须是从以ResultSet.CONCUR_UPDATABLE为参数的,而且resultset必许是从唯一的表中选出来的,还有必须要包含主键。
    所以我是这样创建的:
    String sqlBlob = "select * from test where ID='***' for update";
    然后
    Blob mapBLOB = (Blob)rsBlob.getBlob("pic");  //pic为blob型的
    最后
    rs.updateBlob("pic", mapBLOB);
    rs.updateRow();
    这样就搞定了,口喜口喜!!!!!
    bruni(不如你) 请到这里来:
    http://expert.csdn.net/Expert/topic/1964/1964053.xml?temp=.8519403
    曲曲几分不成敬意,:)