***为什么oracle中blob类型超过4036就存不进去?急!!!***

worldtaxi 2003-08-19 01:51:47
超过4036的文件存进去后记录是增加了,但取出来后内容却是空的,请问是什么原因啊?
我用的方法:
String picPath="/tst.jpg";
File imgFile=new File(picPath);
sql="insert into lobdemo (key,blob_col) values (33,?)"; PreparedStatement pstmt=conn.prepareStatement(sql);
FileInputStream fis=new FileInputStream(picPath); pstmt.setBinaryStream(1,fis,(int)imgFile.length());
pstmt.executeUpdate();
pstmt.close();
...全文
84 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunruiandxwh 2003-09-26
  • 打赏
  • 举报
回复
我也遇到同样的问题。
mountsnow 2003-09-01
  • 打赏
  • 举报
回复
对于流的操作,最好使用Buffer
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
oracle.sql.BLOB content = null;
try {
conn = getConnection();
conn.setAutoCommit(false);
stmt = conn.createStatement();
stmt.executeUpdate(sql);
rs = stmt.executeQuery(sqlBlob);
while (rs.next()) {
content = (oracle.sql.BLOB)rs.getBlob("content");
}
bos = new BufferedOutputStream(content.getBinaryOutputStream());
bis = new BufferedInputStream(sis);
byte[] buffer = new byte[ content.getBufferSize() ];
int bytesRead = 0;
int hasRead = 0;
while( ( bytesRead = bis.read( buffer ) ) != -1 ) {
hasRead += bytesRead;
if (hasRead > fileSize) {
bytesRead = bytesRead - (hasRead - fileSize);
}
bos.write( buffer, 0, bytesRead );

}
bos.flush();
bos.close();
bis.close();
conn.commit();
conn.setAutoCommit(true);
} catch(Exception e1) {
System.out.println("e1: " + e1.getMessage());
try {
conn.rollback();
conn.setAutoCommit(true);
bos.flush();
bos.close();
bis.close();
} catch (Exception e2) {
System.out.println("e2: " + e2.getMessage());
}
} finally {
this.disconnect(rs, stmt, conn);
}
worldtaxi 2003-09-01
  • 打赏
  • 举报
回复
我用以下的方法就没有问题这是问什么啊?
conn.setAutoCommit(false);
sql="insert into lobdemo (key,blob_col) values (" + idkey + ",'0')";
Statement stmt1=conn.createStatement();
stmt1.executeUpdate(sql);
stmt1.execute("commit");
sql = "select blob_col from lobdemo where key=" + idkey + " for update";
res = stmt1.executeQuery(sql);
res.next();
oracle.jdbc2.Blob blob=((oracle.jdbc.driver.OracleResultSet) res).getBLOB(1);
FileInputStream fis = new FileInputStream(imgFile);
OutputStream fos = ((oracle.sql.BLOB)blob).getBinaryOutputStream();
byte[] buffer1 = new byte[1024];
int len;
while ( (len = fis.read(buffer1)) != -1) fos.write(buffer1, 0, len);
stonegump 2003-08-20
  • 打赏
  • 举报
回复
没碰到过这问题啊,blob最大有4G呢。我存过20兆的文件,没有问题,速度稍慢点
zhangbin_zhang 2003-08-19
  • 打赏
  • 举报
回复
用longraw型的吧,没问题。
我也遇到过这个问题,也是存了超过一定大小就存不进去了。

knight_qmh 2003-08-19
  • 打赏
  • 举报
回复
不要用thin
用oci8
jdbc:oracle:oci8:@db
VVV_lucky 2003-08-19
  • 打赏
  • 举报
回复
是不是没空间了呀?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧