客户端文件如何上传后不保存直接存入数据库的blob字段里??我用的jspsmart组件,好像不保存就插入不了。另外我的文件可能是web档案的单一文件(.mht),从blob里取出的时候如果直接输出就都是字符,不知道怎么会事,请高手指教!急等回复!

解决方案 »

  1.   

    InputStream in =request.getInputStream();
    conn=dbcon.getConnection();//获得数据库连接
    ps=conn.prepareStatement("insert into imageTable values(?,?)");
    ps.setString(1,num);//num:是序号
    ps.setBinaryStream(2,in,in.available());
    ps.executeUpdate();
    in.close();
    ps.close();
    conn.close();
      

  2.   

    问题已经基本上解决的差不多了,不过上传的时候必须将文件物理保存在硬盘上才能继续插入到blob字段里,这是我不希望的结果,不知道怎么解决!另外mht文件用流的方式打开的时候需要设置mime类型为message/rfc822
      

  3.   

    bufferReader in = bufferReader(new inputStreamReader(socket.getInputStream()))
    String field = in.readLine()conn=dbcon.getConnection();
    PreparedStatement ps;
    ps=conn.prepareStatement("insert into imageTable values(?,?)");
    ps.setInt(1.xxx);
    ps.setInt(2.xxx);
    ps.execute();