数据库blob类型文件写入本地影片问题 Connection con = null; PreparedStatement pstmt = null; ResultSet rst = null; int i = 0; String sql = "select * from person "; InputStream is = null; OutputStream os = null; try {
long beginTime = System.currentTimeMillis(); Class.forName( "oracle.jdbc.driver.OracleDriver "); con = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:aolei ", "aolei ", "aolei "); pstmt = con.prepareStatement(sql); rst = pstmt.executeQuery(); while (rst.next()) { BLOB blob = (BLOB) rst.getBlob(4); is = blob.getBinaryStream(); File file = new File( "d:/out/output "+i+ ".txt ");
try { os = new FileOutputStream(file); } catch (FileNotFoundException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } byte[] b = new byte[1024]; int len = 0; try { while ((len = is.read(b)) != -1) { os.write(b, 0, len); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }