File file = new File("e:\\ejb.txt");
 Reader  fileReader = new FileReader(file);
Class.forName("oracle.jdbc.driver.OracleDriver");
          Connection con = DriverManager.getConnection("jdbc:oracle:thin:scott/127.0.0.1:1243:myInstance","user","pass");String sql = "insert into table1(obj_id,content) VALUES(?,?)";
       PreparedStatement ps=con.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE ,ResultSet.CONCUR_UPDATABLE );
       ps.setInt(1,2) ;
       ps.setCharacterStream(2 ,fileReader,file.length()) ;//ntext max 450 !
          ps.executeUpdate()  ;sql = "select * from table1 where obj_id= 2";
 ResultSet rs=ps.executeQuery(sql);
 rs.next() ;
 Clob clob= rs.getClob(2) ;          String read = clob.getSubString( 1,(int)clob.length());
      System.out.println(read) ;
      
具体的把读出的内容保存到文件很简单,自己写...
这是对于clob,对于blob也一样

解决方案 »

  1.   

    file-->oracle
    oracle-->file
      

  2.   

    如果不指定具体文件,而是由客户端通过<input type=file>选择一个文件呢?
      

  3.   

    <%@ page import="com.jspsmart.upload.*"%>
    String fileName = "";
             SmartUpload upload = new SmartUpload();
             upload.initialize( this.getServletConfig(), request, response );
             upload.upload();
           Files files = upload.getFiles();
           //here can get all files that have been selected.
           if(files != null && files.getCount() != 0) {
     com.jspsmart.upload.File file = files.getFile(0);
             String name = file.getFileName();
             fileName = name;  file.saveAs( fileName, com.jspsmart.upload.File.SAVEAS_PHYSICAL);
           }这是取得上传的文件并保存..
    然后你在按上面那样保存到数据库...
    也可以不保存直接传到数据库...
      

  4.   

    String sql = "insert into table1(obj_id,content) VALUES(?,?)";
           PreparedStatement ps=con.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE ,ResultSet.CONCUR_UPDATABLE );
           ps.setInt(1,2) ;
           ps.setCharacterStream(2 ,fileReader,file.length()) ;//这一句就是把文件存入数据库拉 !
    ps.executeUpdate()  ;
    这不是吗????
    当然表的名字换成你自己的,字段换成你自己的...
      

  5.   

    请问:如果是用SMARTUPLOAD从网页上传来的一个文件,那么:filereader怎么定议?