统计oracle blob存使用,oracle 存BLOB跟读取

当前位置:我的异常网» 编程 » oracle 存BLOB跟读取

oracle 存BLOB跟读取

www.myexceptions.net  网友分享于:2013-09-26  浏览:55次

oracle 存BLOB和读取

public void savaSoftFile(InputStream inputStream,String userid) {

// 传的是存入数据库图片的id

Connection conn=getConn();

Statement st = null;

BLOB blob = null; // 图片类型

OutputStream outputStream = null; // 输出流

File file = null; // 文件

ResultSet rs = null;

try {

conn.setAutoCommit(false); // 事物由程序员操作

st = conn.createStatement();

st.executeUpdate( "update  SOFTDEPFILE  set  DEPFILE = empty_blob() where ID='"

+ userid + "'");

rs = st.executeQuery("select DEPFILE from SOFTDEPFILE  where id='"

+ userid + "' ");

if (rs.next()) {

blob = (BLOB) rs.getBlob(1);

outputStream = blob.getBinaryOutputStream();

byte[] b = new byte[blob.getBufferSize()];

int len = 0;

while ((len = inputStream.read(b)) != -1) {

System.out.println(len);

outputStream.write(b, 0, len);

}

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

try {

inputStream.close();

outputStream.flush();

outputStream.close();

rs.close();

st.close();

conn.commit();

conn.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

public  void writeImg(OutputStream os,String userid) {

try {

Connection conn=getConn();

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery("select uploadpic from pub_usertable where  userid='"

+ userid + "'");

byte[] b = new byte[1024];

if (rs.next()) {

Blob blob = rs.getBlob(1);

InputStream is = blob.getBinaryStream();

int i = 0;

while ((i = is.read(b)) != -1) {

os.write(b, 0, i);

}

os.close();

is.close();

}

rs.close();

stmt.close();

conn.close();

} catch (Exception e) {

e.printStackTrace();

}

}

文章评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值