Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7934331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:36:58+00:00 2026-06-03T21:36:58+00:00

I have Mysql datatbase, and working on servlet: this is my Table schema: CREATE

  • 0

I have Mysql datatbase, and working on servlet:
this is my Table schema:

 CREATE TABLE Files (
 File_Name               VARCHAR(50),
 File_Data                Blob ,
 File_Date          VARCHAR(20),
 File_Course_Code       VARCHAR(45) REFERENCES Course(Course_Code) ,
 PRIMARY KEY (File_Name , File_Date, File_Course_Code)
  );

And here is the servlet code:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    ServletOutputStream os = response.getOutputStream();
    try {
        InputStream uploadedFile = null;

        DiskFileUpload fu = new DiskFileUpload();
        // If file size exceeds, a FileUploadException will be thrown
        fu.setSizeMax(10000000);

        List fileItems = fu.parseRequest(request);
        Iterator itr = fileItems.iterator();

        while (itr.hasNext()) {
            FileItem fi = (FileItem) itr.next();

            //Check if not form field so as to only handle the file inputs
            //else condition handles the submit button input
            if (!fi.isFormField()) {  // If the form fiel is a file
                uploadedFile = fi.getInputStream();
            }
        }

            // to get the file name:
            String fileName= "String";



            // to extract the date:
            java.util.Date now = new java.util.Date();
            String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss";
            SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
            String strDateNew = sdf.format(now);


            HttpSession session = request.getSession();
            String a = (String) session.getAttribute("fileccode");



            // set connection up: 
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/VC", "root", "");
            PreparedStatement stmt = null;
            stmt = conn.prepareStatement("INSERT INTO Files (File_Name,File_Data,File_Date,File_Course_Code) VALUES (?,? ?,?)");
                  stmt.setString(1,fileName);
            stmt.setBinaryStream(2,uploadedFile);
                  stmt.setString(3,strDateNew);
                  stmt.setString(4,a);
            stmt.executeUpdate();



    } catch (FileUploadException e) {
        os.print(e.getLocalizedMessage());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        os.close();
    }
}

I have seen many posts about this error, but almost all of them were having Syntax error in writing the query.
I have no syntax error i believe.
but maybe (File_Data) as a primary key and default null makes something wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:37:00+00:00Added an answer on June 3, 2026 at 9:37 pm

    Your missing a comma

    VALUES (?,? ?,?)
    

    should be

    VALUES (?,?,?,?)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
Im working with a mysql database via php. I have a table with some
I have one Servlet that does insertion into my database. This is working fine.
Working with MySQL database. I have a store table. The store table has at
I have a code to create VIEW in mysql database which is working fine
I have a java program that connects to a MySql database and it's working
I am working on PHP and database MySQL. I have two tables in SQL
I have a MySQL database, and a particular table in that database will need
Hi I have a MySQL database table points the user can click a button
I am working in a MySQL database. I have added a custom field to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.