时间:2021-07-01 10:21:17 帮助过:15人阅读
2、读取大对象
1 /** 2 * 对取大对象 3 */ 4 @Test 5 public void testReadPic(){ 6 Connection conn=null; 7 Statement st=null; 8 PreparedStatement pst=null; 9 try { 10 conn=DBUtils.getConn(); 11 conn.setAutoCommit(false);//事物不能自动提交 12 st=conn.createStatement(); 13 long start = System.currentTimeMillis(); 14 String sql="select pic from stu where sid=?"; 15 pst=conn.prepareStatement(sql); 16 pst.setInt(1, 1); 17 ResultSet rs = pst.executeQuery(); 18 if(rs.next()){ 19 byte[] bytes = rs.getBytes(1); 20 FileOutputStream fos = new FileOutputStream("d:/kk.jpg"); 21 fos.write(bytes); 22 fos.close(); 23 } 24 25 conn.commit();//提交事务 26 System.out.println("over"); 27 System.out.println(System.currentTimeMillis()-start); 28 } catch (Exception e) { 29 // TODO Auto-generated catch block 30 e.printStackTrace(); 31 } 32 finally{ 33 DBUtils.closeAll(null, st, conn); 34 } 35 }
jdbc插入大对象及读取大对象
标签:input ring 进制 from inpu date out mit save