在數據庫表中定義一個類型為CLOB 的列﹐即可以把文本文件放進來。

解决方案 »

  1.   

    /*
            名称:saveFileToBlob
            功能:把图形文件保存到oracle数据库
        输入参数:无
        输出参数: 0 成功 1 失败
      */
      public int saveFileToBlob(String sDirName,String sCaseNo,String sPerson)
      {
           File[] file = new File(sDirName).listFiles();
           String sFileName="";
           for(int i=0;i<file.length;i++)
           {           if(file[i].isFile() && file[i].getName().indexOf("jpg")!=-1 )
               {             sFileName = file[i].getName();
                 try
                {
                  FileInputStream  FileInput= new FileInputStream(sDirName + "\\"+sFileName);
                  m_connection.setAutoCommit(false);
                  Statement  stmt       = m_connection.createStatement();
                  CallableStatement callStmt = m_connection.prepareCall("call getrowId(?,?)");
                 //取row_id
                  callStmt.registerOutParameter(2, Types.VARCHAR);
                  callStmt.setString(1, "image");
                  callStmt.execute();
                  String strRowId = callStmt.getString(2);
                  String strSqlInsertBlob = "insert into image ....)";
                 stmt.execute(strSqlInsertBlob);
                  ResultSet rts = stmt.executeQuery("select image from image ......");
                  BLOB blob = null;
                 if(rts.next()!=false)
                 {
                   blob = ( (OracleResultSet) rts).getBLOB(1);
                   OutputStream out = blob.getBinaryOutputStream(blob.length());
                   int chunk = blob.getChunkSize();
                   byte[] buffer = new byte[chunk];
                   int flength = -1;
                   while ( (flength = FileInput.read(buffer)) != -1)
                     out.write(buffer, 0, flength);
                    out.close();
                   FileInput.close();
                   m_connection.commit();
                   rts.close();
                   stmt.close();
                   callStmt.close();             }
                 else {
                   FileInput.close();
                    rts.close();
                    stmt.close();
                    callStmt.close();
               }
                }
                catch(Exception e)
                 {
                   System.out.println(e.toString());
                   System.out.println(e.getClass().toString());
                    return 1;
                   }           }
                 }
           deleteFile(sDirName);
          if (m_connection!=null)
           try
           {
                m_connection.close();
           }
           catch (Exception e) {}
        return 0;  }
      

  2.   

    BLOB  OracleResultSet都是什么包里的啊?
      

  3.   

    怎么能insert update delete,  bolb类型的字段???help!