现在得到oracle数据库的一个BLOB,这个BLOB是一个上传的文件,现在我能得到这个byte[],如何下载?java代码里边如何写?求指点思路...这个byte[]是整个文件,如何用outputstream把它下载下来?

解决方案 »

  1.   

    public void query()throws Exception
    {
    Connection conn=null;
    PreparedStatement pst=null;
    ResultSet rs=null;
    try
    {
    conn=TextJdbc.newInstance().getConnection();
    pst=conn.prepareStatement("select id,name,picontext from pic");
        rs=pst.executeQuery();
        while(rs.next())
        {
         int pid=rs.getInt(1);
         String name=rs.getString(2);
         java.sql.Blob blob=rs.getBlob(3);
         int len=(int)blob.length();
         byte b[]=blob.getBytes(1, len);
         writer(b,name);
         System.out.println(pid+"\t"+name);
        }
    }
    finally
    {
    TextJdbc.newInstance().close(rs, pst, conn);
    }
    }
    public void writer(byte[] b,String name)throws Exception
    {
    FileOutputStream fos=null;
    try
    {
    fos=new FileOutputStream("d:\\ywx\\"+name+".jpg");
    fos.write(b);

    }
    finally
    {
    fos.close();
    }
    }不知道是否符合你的要求。