如何把图片存入Oracle数据库?

[复制链接]
查看11 | 回复1 | 2009-9-4 16:10:43 | 显示全部楼层 |阅读模式
class.forname("oracle.jdbc.driver.oracledriver");connection con = drivermanager.getconnection("jdbc:oracle:thin:@localhost:1521:testdb", "test", "test");//处理事务con.setautocommit(false);statement st = con.createstatement();//插入一个空对象st.executeupdate("insert into blobimg values(103,empty_blob())");//注意这里用了oracle自带的函数//用for update方式锁定数据行resultset rs = st.executequery("select contents from blobimg where id=103 for update");if (rs.next()) {//得到java.sql.blob对象,然后cast为oracle.sql.bloboracle.sql.blob blob = (oracle.sql.blob) rs.getblob(1).;//到数据库的输出流outputstream outstream = blob.getbinaryoutputstream();//这里用一个文件模拟输入流file file = new file("d:"proxy.txt");inputstream fin = new fileinputstream(file);//将输入流写到输出流byte[] b = new byte[blob.getbuffersize()];int len = 0;while ( (len = fin.read(b)) != -1) {outstream.write(b, 0, len);//blob.putbytes(1,b);}//依次关闭(注意顺序)fin.close();outstream.flush();outstream.close();con.commit();con.close();
回复

使用道具 举报

千问 | 2009-9-4 16:10:43 | 显示全部楼层
以byte数组存入即可。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行