我那时候插到long里面是用
PreparedStatement.setBinaryStream的

解决方案 »

  1.   

    long 类型不能使用 insert 语句直接插入的!
    下面是个函数!
    自己看看,再想想,好吗?
      

  2.   

    File file = new File(request.getRealPath("") + "\\Sample.jpg");
    sql = "insert into picture(filename, picture) values(?, ?)";
    PreparedStatement pstmt = conn.prepareStatement(sql);
    FileInputStream fis = new FileInputStream(file);
    pstmt.setString(1, file.getName());
    pstmt.setBinaryStream(2, fis, fis.available());
    if (1 != pstmt.executeUpdate())
    {
    System.err.println("Incorrect value returned during picture insert");
    }
    pstmt.close();
    fis.close();
      

  3.   

    不好意思!快了一步按按钮!!表: create table streamexample (NAME varchar2 (256), DATA long)File file = new File ("StreamExample.java");
    // 下面是插入数据
    InputStream is = new FileInputStream ("StreamExample.java");
    PreparedStatement pstmt = 
      conn.prepareStatement ("insert into streamexample (data, name) values (?, ?)");
      pstmt.setAsciiStream (1, is, (int)file.length ());
      pstmt.setString (2, "StreamExample");
      pstmt.execute ();//下面是读数据
     ResultSet rset = 
      stmt.executeQuery ("select DATA from streamexample where NAME='StreamExample'");
        
      if (rset.next ())
      {
          InputStream gif_data = rset.getAsciiStream (1);
          FileOutputStream os = new FileOutputStream ("example.out");      
          int c;
          while ((c = gif_data.read ()) != -1)
            os.write (c);
          os.close ();
      }