我插入成功了,但是取出来的是否发现size都是0,以下是我用过的代码:
方法一.
PreparedStatement pstmt = con.prepareStatement("Insert into InsertFile values(3,EMPTY_BLOB())");
pstmt.executeUpdate();
pstmt = con.prepareStatement("Update InsertFile set InsertFile = ? where RECID=3");
pstmt.setBinaryStream(1,fin,fileSize);
pstmt.executeUpdate();
方法二.
PreparedStatement pstmt = con.prepareStatement("Insert into InsertFile(RECID,INSERTFILE) Values(?,?)");
pstmt.setInt(1,1);
pstmt.setBinaryStream(2, fin, fileSize);
pstmt.executeUpdate();方法3.
PreparedStatement pstmt = con.prepareStatement("UPDATE InsertFile SET INSERTFILE = ? WHERE RECID=2");
pstmt.setBinaryStream(1, fin, fileSize);
pstmt.executeUpdate();请指点!!!!
方法一.
PreparedStatement pstmt = con.prepareStatement("Insert into InsertFile values(3,EMPTY_BLOB())");
pstmt.executeUpdate();
pstmt = con.prepareStatement("Update InsertFile set InsertFile = ? where RECID=3");
pstmt.setBinaryStream(1,fin,fileSize);
pstmt.executeUpdate();
方法二.
PreparedStatement pstmt = con.prepareStatement("Insert into InsertFile(RECID,INSERTFILE) Values(?,?)");
pstmt.setInt(1,1);
pstmt.setBinaryStream(2, fin, fileSize);
pstmt.executeUpdate();方法3.
PreparedStatement pstmt = con.prepareStatement("UPDATE InsertFile SET INSERTFILE = ? WHERE RECID=2");
pstmt.setBinaryStream(1, fin, fileSize);
pstmt.executeUpdate();请指点!!!!
PreparedStatement pstmt = con.prepareStatement("Select * from INSERTFILE where RECID = 1");
ResultSet rs = pstmt.executeQuery();
int len = 0 ;
int recId = 0;
if (rs.next()) {
InputStream bl= rs.getBinaryStream("INSERTFILE") ; //rs.getBlob("INSERTFILE");
recId = rs.getInt("RECID");
if (bl != null){
len = (int)bl.available();;
System.out.println(len);
System.out.println(recId);
}
结果发现 bl不为null 但是 len为0;
结合上面blob的写方法,我的这两个读写方法错误在那里,请指教!!!1
介绍怎么做这件事,还有一点,你用的jdbc应该是817以后的,以前的多少
有些问题。
inputstream = rs.getBlob("Insertfile").getBinaryStream();
inputstream.write(...);
rs.updaterow();
不过分照样发,感谢skyyoung(路人甲)和 yikesfish(yikes) 的恢复