2015-07-13 70 views
0

你好,我是在JSP编程新手。我试图在PostgreSQL数据库中插入一个图像与字节字段。这是我的代码到目前为止。的setBinaryStream(INT,为InputStream)尚未实现

JSP代码

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
    <!DOCTYPE html> 
    <html> 
     <head> 
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
      <title>JSP Page</title> 
     </head> 
     <body> 
      <h1>Test image</h1> 
      <form action="Upload" method="post" enctype="multipart/form-data"> 
       <input type="text" name="description" /> 
       <input type="file" name="file" /> 
       <input type="submit" /> 
      </form> 
     </body> 
    </html> 

servlet代码

protected void doPost(HttpServletRequest request, HttpServletResponse response) 
       throws ServletException, IOException { 
InputStream inputStream = null; 

     // obtains the upload file part in this multipart request 
     Part filePart = request.getPart("file"); 
     if (filePart != null) { 
      // debug messages 
      System.out.println(filePart.getName()); 
      System.out.println(filePart.getSize()); 
      System.out.println(filePart.getContentType()); 

      // obtains input stream of the upload file 
      inputStream = filePart.getInputStream(); 
     } 

     try { 
      Class.forName("org.postgresql.Driver"); 
      Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:8084/hgcirequestproject", "appdev2", "[email protected]"); 

      PreparedStatement ps = con.prepareStatement("insert into tbl_testimage (test) values (?)"); 
     ps.setBinaryStream(1, inputStream); 

      ps.executeQuery(); 
      out.println("success"); 
      con.close(); 
      ps.close(); 
     } catch (Exception e) { 
      System.out.println(e.toString()); 

     } 



    } 

} 

我得到了错误.setBinaryStream(INT,为InputStream)尚未实现。 任何帮助将不胜感激。感谢

回答

相关问题