浏览 3278 次
锁定老帖子 主题:Orcale BLOB 乱码问题
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2007-06-14
这个是存入的方法 private void insertBlob(Connection conn){ try{ conn.setAutoCommit(false); Statement st = conn.createStatement(); st.executeUpdate("insert into test1 values('hxc',empty_blob())"); ResultSet rs = st.executeQuery( "select * from test1 where name='hxc' for update"); if (rs.next()) { oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("xml"); OutputStream outStream = blob.getBinaryOutputStream(); File file = new File("c:\\ttt.txt"); InputStream fin = new FileInputStream(file); byte[] b = new byte[blob.getBufferSize()]; int len = 0; while ( (len = fin.read(b)) != -1) { outStream.write(b, 0, len); //blob.putBytes(1,b); } fin.close(); outStream.flush(); outStream.close(); conn.commit(); }}catch(Exception e){ e.printStackTrace(); } } 取出方法: while(rs.next()){ BLOB blob = (BLOB)rs.getBlob("xml"); byte[] bb = blob.getBytes(); FileOutputStream out = new FileOutputStream("c:\\t1.txt"); out.write(bb); out.flush(); 请大看帮我想想办法,, 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |