byte[]里面是图片信息,如何存入oracle

解决方案 »

  1.   

    PreparedStatement setBytes(int parameterIndex, byte[] x) 
    不知道可以不,看看对应oracle数据类型。
      

  2.   

    setBlob(int i, new SerialBlob(byte[] b))
      

  3.   


    这个是做什么的?
    用PreparedStatement setBytes(int parameterIndex, byte[] x),库里面不插入。。
      

  4.   

    用Blob写入要用流,lz搜索下,java写入Blob数据,网上很多
      

  5.   

    setBlob(int i, new SerialBlob(byte[] b))
    这个不行会这句话会有异常
      

  6.   

    如果是插入数据,先插入一个empty_blob(),更新数据就update为empty_blob()
    然后select 一次,获得该 blob
    比如获得的blob 为
    Blob blob = resultset.getBlob("xxx");
    然后调用
    OutputStream os = blob.setOutputStream(1);
    os.write(your_byte);
      

  7.   


     try{
       conn = this.getConnection();
       conn.setAutoCommit(false);
        java.sql.Statement st = conn.createStatement();
            String sql1 = "insert into test_image(test_id,image) values ("123",empty_blob)";
        System.out.println("--------->"+sql1);
            String stl2 = "select image from test_image where test_id='"+test.getId()+"' for update";
        ResultSet rs = st.executeQuery(stl2);
        OutputStream outStream = null;
        if (rs.next())
        {
                    oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("image");
           outStream = blob.getBinaryOutputStream();
     outStream.write(byte[],0, byte[].length);
        }
        outStream.flush();
        outStream.close();
        conn.commit();
        conn.close();
       }