package com.sc.dzzw.dagl;import com.sc.system.sys_manage.SqlAction;
import java.io.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.*;
import javax.servlet.http.*;public class ReadDoc extends HttpServlet
{    public ReadDoc()
    {
    }    public void init()
        throws ServletException
    {
    }    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String Docid = request.getParameter("Docid");
        ServletOutputStream sos = response.getOutputStream();
        ResultSet rset = null;
        String sql = "";
        try
        {
            SqlAction sqldb = new SqlAction();
            sql = String.valueOf(String.valueOf((new StringBuffer("select govdoc_text from govdoc where govdoc_id='")).append(Docid).append("'")));
            for(rset = sqldb.ExecQuery(sql); rset.next(); sos.close())
            {
                InputStream is = rset.getBinaryStream(1);
                for(byte buffer[] = new byte[1]; is.read(buffer) != -1; sos.write(buffer)) { }
            }            rset.close();
            sqldb.CloseAll();
        }
        catch(SQLException sqlexception) { }
        finally
        {
            try
            {
                rset.close();
            }
            catch(SQLException sqlexception1) { }
        }
    }    public void destroy()
    {
    }
}package untitled2;
import java.sql.*;
import java.io.*;
import oracle.jdbc.*;
import oracle.sql.*;public class Stream{
            public void blobin(String FileName,String bc)
                    throws Exception{
                 Connection conn =null;
                 try {
                 Class.forName("oracle.jdbc.driver.OracleDriver");
                 conn =DriverManager.getConnection ("jdbc:oracle:thin:@192.168.100.111:1521:oracle8", "dzzw", "dzzw");
                 conn.setAutoCommit(false);
                 } catch (Exception e) {
                                             // If there is any security exception, ignore it
                                              // and use the default
                        }
                 //    SqlAction sa = new SqlAction();
                    String sql = "";
                    sql = "select govdoc_text from govdoc where govdoc_id='"+bc+"' for update";
                //     ResultSet rset =  sa.ExecQuery(sql);
                Statement stmt = conn.createStatement ();
                ResultSet rset = stmt.executeQuery(sql);
                     while (rset.next ()){
                         BLOB blob = ((OracleResultSet)rset).getBLOB (1);
                         fillBlob (blob, FileName);
                     }
                    rset.close();
                    stmt.close();
                    conn.close();
              }                  static void fillBlob (BLOB blob,String FileName)
                    throws Exception
                        {
                            OutputStream outstream =blob.getBinaryOutputStream();
                             File f=new File(FileName);
                             FileInputStream fin=new FileInputStream(f);
                             long filelength=0;
                            filelength =f.length();
                            byte b[]=new byte[(int)filelength];
                            while(true){
                             int leng=fin.read(b);
                            if(leng==-1) break;
                            outstream.write(b,0,leng);
                          }
                           outstream.close();
                        }
}