return con;
}
public static void setCon(Connection con) {
InitDB.con = con;
}
public static ResultSet getRs() {
return rs;
}
public static void setRs(ResultSet rs) {
InitDB.rs = rs;
}
public static Statement getStmt() {
return stmt;
}
public static void setStmt(Statement stmt) {
InitDB.stmt = stmt;
}
}
/*
* 插入Blob数据 如:图片
*/
class InsertBlobData{
private ResultSet rs=null;
private InitDB idb=null;
InsertBlobData(){
idb=new InitDB();
}
public void insertBlob(String sql1) throws SQLException{
Connection con=idb.getCon();
try{
con.setAutoCommit(false);//不设置自动提交
BLOB blob = null; //插入空的Blob
PreparedStatement pstmt = con.prepareStatement("insert into cdl_test(sid,img) values(?,empty_blob())");
pstmt.setString(1,"100");
pstmt.executeUpdate();
pstmt.close();
rs=con.createStatement().executeQuery(sql1);
while(rs.next()){
System.out.println("rs length is:");
oracle.sql.BLOB b=(oracle.sql.BLOB )rs.getBlob("img");
System.out.println("cloblength is:"+b.getLength());
File f=new File("d:\\img\\1.jpg");
System.out.println("file path is:"+f.getAbsolutePath());
BufferedInputStream in=new BufferedInputStream(new FileInputStream(f));
BufferedOutputStream out=new BufferedOutputStream(b.getBinaryOutputStream());
int c;
while ((c=in.read())!=-1) {
out.write(c);
}
in.close();
out.close();
}
con.commit();
}catch(Exception e){
con.rollback();//出错回滚
e.printStackTrace();
}
}
}
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|