?? oracleblobparseblh.java
字號:
} catch (IOException ex1) {
}
finally {
try {
if(ins!=null){
ins.close();
}
} catch (IOException io) {
}
}
byteout=bytearray.toByteArray();
}
**/
ByteArrayInputStream byteins=new ByteArrayInputStream(bytearray.toByteArray());
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(byteins));
ZipEntry entry=null;
try {
entry = zis.getNextEntry();
} catch (IOException ex2) {
}
if (entry!= null) {
System.out.println("entry name=" + entry.getName());
iszip=true;
dns=new DataInputStream(zis);
}
if(iszip){
byte[] a = new byte[1024];
int l = 0;
try {
while ((l = dns.read(a)) != -1) {
bytearrayn.write(a, 0, l);
}
} catch (IOException ex1) {
}
finally {
try {
if(con!=null){
con.close();
}
if(ins!=null){
ins.close();
}
if(dns!=null){zis.closeEntry();zis.close();dns.close();}
} catch (SQLException se) {
}catch(IOException io){
}
}
byteout = bytearrayn.toByteArray();
}else{
byteout = bytearray.toByteArray();
}
return byteout;
}
public byte[] selectblobwdsc(String id,String swjg){
int ret=0;
byte[] byteout=null;
GZDAfileDetailVO detail=null;
BLOB blob=null;
List list=null;
InputStream ins=null;
ByteArrayOutputStream bytearray=new ByteArrayOutputStream();
Map para=new HashMap();
para.put("MB_DM",new String(id));
para.put("MB_SWJG",new String(swjg));
list=selectfile("selectfilewdsc",para);
if(list.size()>=1){
detail=(GZDAfileDetailVO)list.get(0);
blob=(BLOB)detail.getFiledoc();
try {
ins = blob.getBinaryStream();
} catch (SQLException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
byte[] b = new byte[1024];
int len = 0;
try {
while ((len = ins.read(b)) != -1) {
bytearray.write(b, 0, len);
}
} catch (IOException ex1) {
}
finally {
try {
ins.close();
} catch (IOException io) {
}
}
byteout=bytearray.toByteArray();
}
return byteout;
}
public InputStream getblob(String url){
GZDAfileDetailVO detail=null;
BLOB blob=null;
List list=null;
InputStream ins=null;
/**
list=selectfile("selectfile",url);
if(list.size()>=1){
detail=(GZDAfileDetailVO)list.get(0);
blob=(BLOB)detail.getFiledoc();
try {
ins = blob.getBinaryStream();
} catch (SQLException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
}
**/
//try {
ins=getFileBlob(url);
//ins = blob.getBinaryStream();
//} catch (SQLException ex) {
//}
return ins;
}
public OutputStream getblobout(String url){
GZDAfileDetailVO detail=null;
BLOB blob=null;
List list=null;
OutputStream ous=null;
InputStream ins=null;
/**
list=selectfile("selectfile",url);
if(list.size()>=1){
detail=(GZDAfileDetailVO)list.get(0);
blob=(BLOB)detail.getFiledoc();
try {
ins = blob.getBinaryOutputStream();
} catch (SQLException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
}
**/
try {
ins=getFileBlob(url);
//ous = blob.getBinaryOutputStream();
byte[] b = new byte[1024];
int len = 0;
while ((len = ins.read(b)) != -1) {
ous.write(b, 0, len);
}
} catch (Exception ex) { }
return ous;
}
public int saveblob(String urlstring,InputStream in){
int rei=0;
//ZipInputStream zipins=new ZipInputStream(in);
//try {
// zipins.getNextEntry();
//} catch (IOException ex1) {
// throw new RuntimeException("50001"+ex1.toString());
//}
//DataInputStream din=new DataInputStream(zipins);
/**
GZDAfileDetailVO detail=new GZDAfileDetailVO();
detail.setUrl(urlstring);
BLOB blob=null;
List list=null;
try {
blob = BLOB.empty_lob();
} catch (SQLException e1) {
// TODO 自動生成 catch 塊
e1.printStackTrace();
}
detail.setFiledoc(blob) ;
daoManager.startTransaction();
rei=inserttfile("insertfile",detail);
list=selectfile("selectfile",urlstring);
if(list.isEmpty()){
System.out.println("插入空BLOB出錯!");
}
GZDAfileDetailVO td=(GZDAfileDetailVO)list.get(0);
BLOB lob=(BLOB)td.getFiledoc();
OutputStream outStream=null;
try {
//System.out.println(td.getFiledoc());
outStream= lob.getBinaryOutputStream();
} catch (SQLException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
byte[] b;
int len = 0;
try {
b = new byte[lob.getBufferSize()];
while ((len = in.read(b)) != -1) {
outStream.write(b, 0, len);
//lob.putBytes(1,b);
}
} catch (IOException e2) {
// TODO 自動生成 catch 塊
e2.printStackTrace();
}
catch (SQLException e2) {
// TODO 自動生成 catch 塊
e2.printStackTrace();
}
finally {
try {
if(outStream!=null){
outStream.flush();
outStream.close();
}
} catch (IOException io) {}
}
//detail.setUrl("2111");
//detail.setFiledoc(lob) ;
//rei=inserttfile("insertfile",detail);
daoManager.commitTransaction();
**/
Connection con=null;
weblogic.jdbc.vendor.oracle.OracleThinBlob blob=null;
OutputStream outStream=null;
//try {
// blob = BLOB.empty_lob();
//} catch (SQLException e1) {
// TODO 自動生成 catch 塊
// e1.printStackTrace();
//}
try {
con = JDBCLocator.getInstance().getJDBCConnection();
con.setAutoCommit(false);
Statement st = con.createStatement();
st.executeUpdate("insert into T_GZDA_FILEMANAGERDETAIL values('"+urlstring+"',empty_blob())");
ResultSet rs = st.executeQuery("SELECT url, filedoc FROM T_GZDA_FILEMANAGERDETAIL WHERE url='"+urlstring+"' for update");
while(rs.next()) {
blob =(weblogic.jdbc.vendor.oracle.OracleThinBlob)rs.getBlob("filedoc");
}
outStream = blob.getBinaryOutputStream();
InputStream ins=createZipStream(in);
byte[] b;
int len = 0;
try {
b = new byte[blob.getBufferSize()];
while ((len = ins.read(b)) != -1) {
outStream.write(b, 0, len);
//lob.putBytes(1,b);
}
} catch (IOException e2) {
// TODO 自動生成 catch 塊
e2.printStackTrace();
}
catch (SQLException e2) {
// TODO 自動生成 catch 塊
e2.printStackTrace();
}
finally {
try {
if(outStream!=null){
outStream.flush();
outStream.close();
}
} catch (IOException io) {}
}
rei=1;
// sqlMap.commitTransaction();
} catch (SQLException ex) {
System.out.println(ex.toString());
}finally{
try {
if(con!=null){
con.commit();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -