⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oracleblobparseblh.java

📁 以前做的一个j2ee的项目
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
              } 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 + -