Attempting to send an image from jsp to servlet then to DB2 database

Viewed 44

I am using connection pooling to send and image from jsp to servlet then to DB2. My form enctype is multipart/form-data.

Code in Servlet: protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    System.out.println("**IN SaveNoteContent POST**");
    
    int id = Integer.parseInt(request.getParameter("ID"));
    System.out.println("Note ID:  " + id);
    
    String noteText = request.getParameter("noteText");
    System.out.println(noteText);
    
    
    Part filePart = request.getPart("file");
    String fileName = Paths.get(filePart.getSubmittedFileName()).getFileName().toString();
    System.out.println(filePart);
    System.out.println("FileName:  " + fileName);
    
    
    InputStream fileContent = filePart.getInputStream();
    
    ConnectionPool pool = ConnectionPool.getInstance("jdbc/cmmill26");
    connection = pool.getConnection();
    
    cn = new CreateNote(connection);
    
    cn.add_content(noteText,fileContent,id);
    
   
    
}

Separate java class.

public void add_content(String body, InputStream image, int id) throws IOException {
    
    
    System.out.println("Beginning of adding note content...");
    
    String query = "INSERT INTO note_content(body, image, audio, note_id_content) VALUES (?,?,?,?)";
    
    
    try
    {
        System.out.println(image);

        PreparedStatement ps;
        ps = dbConnection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
        ps.setString(1,body);
        ps.setBinaryStream(2,image);
        // I was going to attempt to also send audio file after successfully uploading the image to blob.
        ps.setBinaryStream(3, image);
        ps.setInt(4,id);
        ps.executeUpdate();

    }
    catch (SQLException e)
    {
        System.out.println(e.getMessage());
    } // end try catch
    
    
}

I'v tried setBlob and setBinaryStream Receiving this error: java.lang.AbstractMethodError: Method com/ibm/db2/jcc/am/zo.setBinaryStream(ILjava/io/InputStream;)V is abstract at com.ibm.db2.jcc.am.zo.setBinaryStream(Unknown Source)

0 Answers
Related