blob字段的长度限制是:?????

The_east_key 2002-03-20 10:12:22
我用JAVA-JDBC-ORACLE向blob字段插入文件,小的文件可以,如1,2k,但是一个35k的文件怎么也插不进去。为是么?请帮忙,谢谢!
代码如下:
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn= DriverManager.getConnection("jdbc:oracle:thin:@sunxiaoming:1521:sxm", "sunxiaoming", "sunxiaoming");
conn.setAutoCommit(false);
Statement stmt=conn.createStatement();

File file=new File("jbWheel.zip");
InputStream is=new FileInputStream(file);
System.out.print(file.length());

PreparedStatement pstmt=conn.prepareStatement("insert into test values (?,?)");
pstmt.setInt(1,1234);
pstmt.setBinaryStream(2,is,(int)file.length());
pstmt.executeUpdate();

pstmt.close();
stmt.close();
conn.close();
...全文
1577 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
coldbloodfox 2002-03-20
  • 打赏
  • 举报
回复
(三)用jdbc处理lob
exmple 4.
首先是Getting BLOB and CLOB Locators from a Result Set
// Select LOB locator into standard result set.
ResultSet rs =stmt.executeQuery ("SELECT blob_col, clob_col FROM lob_table");
while (rs.next())
{// Get LOB locators into Java wrapper classes.
oracle.jdbc2.Blob blob = (oracle.jdbc2.Blob)rs.getObject(1);
oracle.jdbc2.Clob clob = (oracle.jdbc2.Clob)rs.getObject(2);
[...process...]
}
然后是Read BLOB data from BLOB locator.
InputStream byte_stream = my_blob.getBinaryStream();
byte [] byte_array = new byte [10];
int bytes_read = byte_stream.read(byte_array);
和Writing BLOB Data
java.io.OutputStream outstream;
// read data into a byte array
byte[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
// write the array of binary data to a BLOB
outstream = ((BLOB)my_blob).getBinaryOutputStream();
outstream.write(data);
还有Passing a BLOB Locator to a Prepared Statement
OraclePreparedStatement ops = (OraclePreparedStatement)conn.prepareStatement
"INSERT INTO blob_table VALUES(?)");
ops.setBLOB(1, my_blob);
ops.execute();
coldbloodfox 2002-03-20
  • 打赏
  • 举报
回复
有一个JDBC例子给你好了
The_east_key 2002-03-20
  • 打赏
  • 举报
回复
问题已经解决,非常感谢!
lhb_apple 2002-03-20
  • 打赏
  • 举报
回复
BLOB和CLOB最大可以有4G
lhb_apple 2002-03-20
  • 打赏
  • 举报
回复
使用SQLJ可以直接操作BLOB字段,详细自己看,
coldbloodfox 2002-03-20
  • 打赏
  • 举报
回复
我好象看出来了
你的代码好象只适合小的数据记住我上面说的一般处理lob应该用
dbms_lob包,api,oic。
那样你的数据量只要不超过4个G就应该可以了
你试验一下:)
coldbloodfox 2002-03-20
  • 打赏
  • 举报
回复
一般我的处理方法是使用dbms_lob,api,oic
对了请你把Oracle报的错误信息给我详细写出来。。
好帮你推一下
coldbloodfox 2002-03-20
  • 打赏
  • 举报
回复
blob是二进制lob存储二进制数据最长可达4GB在数据库中保存数据
所以应该没问题
现在我正在工作,代码没时间看
请允许我下班的时候给你推推

2,598

社区成员

发帖
与我相关
我的任务
社区描述
Sybase相关技术讨论区
社区管理员
  • Sybase社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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