3

first i created a 2 sql table one is functioning and the other is not the code in my java class is

    try {                           
            PreparedStatement ps1 = con.prepareStatement("INSERT INTO pattable(surname,first,middle,add,contact,email,bdate,genderr) values(?,?,?,?,?,?,?,?);");
            ps1.setString(1, surname);
            ps1.setString(2, first);
            ps1.setString(3, middle);
            ps1.setString(4, add);
            ps1.setString(5, contact);
            ps1.setString(6, email);
            ps1.setString(7, bdate);
            ps1.setString(8, genderr);
            ps1.execute(); 
            ps1.close();
            con.close();
    }
            catch(SQLException e){
                e.printStackTrace();
            }
}

According to console the error might be triggering at line ps1.execute in java with the line "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'add,contact,email,bdate,genderr)" please help Thanks for the Reply really need it for case study :)

1
  • instead if u want the add column name u can use [add] this will be acceptable in sql server. Commented Mar 2, 2021 at 5:36

2 Answers 2

12

You have one column name add ,this is reserved keyword in mysql .check here you cannot use that as your column name that the reason of error you are getting .

Sign up to request clarification or add additional context in comments.

1 Comment

@JustaNewProgrammer check stackoverflow.com/questions/2889871/…
0

Your syntax is wrong, I'd review https://www.w3schools.com/sql/sql_insert.asp to find your problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.