uploading file in postgres database using java servlet

Course Queries Syllabus Queries 2 years ago

7.96K 1 0 0 0

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 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