我的oracle数据表名sst_y_news,字段为:id:number,name:varchar2(40),content blob
我的第一个页addnew.jsp面中有两个输入框:name和content,其中name的输入框为text类型,而content为textarea
现在addnewscheck.jsp中获取到了content里面的数据,我想把content的数据插入到sst_y_news表中的content字段中,其中content字段为blob类型,请问该如何写代码,谢谢

解决方案 »

  1.   

    我做过的一个例子(b为clob字段),适当做下修改就可以了
    public int insertInfo() throws SQLException, IOException
        {
            int result = 0;
            connection = this.getConnection();
    //        connection.setAutoCommit(false);
            Statement stmt = connection.createStatement();
            stmt.executeUpdate("insert into txjblob values(2,EMPTY_BLOB())");
            ResultSet rs = stmt.executeQuery("SELECT b FROM txjblob WHERE x=2 FOR UPDATE NOWAIT");         FileInputStream fin;
            fin = new FileInputStream("D:\\bcarq.gif");
            byte[] blobBuf = new byte[(int)fin.available()];
            fin.read(blobBuf);
            fin.close();        if(rs.next())
            {
                System.out.println(blobBuf.length);
                BLOB blob = (oracle.sql.BLOB)rs.getBlob(1);
                OutputStream out = blob.getBinaryOutputStream();
                out.write(blobBuf);
                out.close();
                connection.commit();
            }
            stmt.close();
    //        connection.setAutoCommit(true);
            this.closeConnection();
            return result; 
        }
      

  2.   

    这个例子我也有,但是我的content是串很长的字符串,请问该怎么把这个获得的字符串插入到blob字段中,用二进制流的形式该怎么写代码,或者用其他什么办法该怎么写,谢谢
      

  3.   

    参考:http://java.ccidnet.com/art/3741/20031225/520063_1.html