uploading file in postgres database using java servlet

Course Queries Syllabus Queries 3 years ago

7.69K 1 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago


Hi I want to upload file in postgres database using java servlet but I am not understanding how to set prepared statement for file as we should use bytea for postgres not blob. Can you help to resolve this issue. I tried using getBytes(), BinaryStream but I am getting errors as

java.lang.AbstractMethodError: Method org/postgresql/jdbc3g/Jdbc3gPreparedStatement.setBinaryStream(ILjava/io/InputStream;)V is abstract

Below is my html code

<form method="post" action="Upload"  enctype='multipart/form-data'>

         id="onelevel" name="onelevel">
        

id="twolevel" name="twolevel">

id="threelevel" name="threelevel">

id="fourlevel" name="fourlevel">

id="fivelevel" name="fivelevel">

class="docu" name="docu"> type="file" name="data" accept=".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" > <button>Uploadbutton>
form>

Here is my java code

package fileupload;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

import dbConnection
                                                
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum