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 502055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:15:10+00:00 2026-05-13T06:15:10+00:00

I use prepareStatement() when the id is a key of my SQL table and

  • 0

I use prepareStatement() when the id is a key of my SQL table and it will be created by SQL and I want to use this statement :(what should I write instead of X in the first column of SQL table(reminder:SQL create it automatically)

File file = new File(pathFile);
            FileInputStream input = new FileInputStream(file);


            query = ("insert into birthtable VALUES(?,?,?,?,?,?,?,?)");
            pstmt = (PreparedStatement) conn.prepareStatement(query);
            pstmt.setInt(1,**X** )
            pstmt.setString(2, name);
            pstmt.setString(3, family);
            pstmt.setString(4, fatherName);
            pstmt.setString(5, mName);
            pstmt.setString(6, dOfBirth);
            pstmt.setString(7, pOfBirth);
            // Method used to insert a stream of bytes
            pstmt.setBinaryStream(8, input);




            pstmt.executeUpdate();

I have done what you all say
but I have this exception??

java.sql.SQLException: Column count doesn't match value count at row 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922)
    at database.Manager.addBirth(Manager.java:76)
    at AdminGUI.AddNewBornInformation.submit(AddNewBornInformation.java:358)
    at AdminGUI.AddNewBornInformation.setButtonActionPerformed(AddNewBornInformation.java:282)
    at AdminGUI.AddNewBornInformation.access$800(AddNewBornInformation.java:28)
    at AdminGUI.AddNewBornInformation$9.actionPerformed(AddNewBornInformation.java:139)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6038)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
    at java.awt.Component.processEvent(Component.java:5803)
    at java.awt.Container.processEvent(Container.java:2058)
    at java.awt.Component.dispatchEventImpl(Component.java:4410)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    at java.awt.Container.dispatchEventImpl(Container.java:2102)
    at java.awt.Window.dispatchEventImpl(Window.java:2429)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
  • 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-05-13T06:15:10+00:00Added an answer on May 13, 2026 at 6:15 am

    If you have specified the type of that column as int and auto-increment e.g.

    `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
    

    then you don’t need to supply any value at all, so you can start the prepared statement params at 1 with name.

     query = ("insert into birthtable (nameCol, familyCol, fatherNameCol, mNameCol, dOfBirthCol, pOfBirthCol, inputCol) VALUES(?,?,?,?,?,?,?)");
            pstmt = (PreparedStatement) conn.prepareStatement(query);
            pstmt.setString(1, name);
            pstmt.setString(2, family);
            pstmt.setString(3, fatherName);
            pstmt.setString(4, mName);
            pstmt.setString(5, dOfBirth);
            pstmt.setString(6, pOfBirth);
            // Method used to insert a stream of bytes
            pstmt.setBinaryStream(7, input);
    

    Note that, as others have said, you must include the column names, whatever they might be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This prepared statement seems like valid SQL to me. PreparedStatement dropTable = cnx.prepareStatement( DROP
I saw this example somewhere: rs = connection.prepareStatement(select * from table).executeQuery(); Could I use
Connection conn = getDBConnection(); //MYSQL CONNECTION. conn.prepareStatement(use testspl).execute(); conn.prepareStatement(SOURCE c:\Test.sql).execute() Is this right way
I want to add a trigger that will keep on updating autoincrement column by
I'm having some trouble trying to use timestamp2 instead of Timestamp in SQL Server
I use this code to fetch data from database table. public List<Dashboard> getDashboardList() throws
I have a SQL query running using something like this: PreparedStatement pstmt = dbConn.prepareStatement(sqlQuery);
I'm trying to use the following code to run a PL/SQL statement on my
I have this Java method which I will use to insert data from JSF
I want to get number of rows in SQL. I use select ROWNUM,FULL_NAME from

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.