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 :)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

2 Answers2

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 .

Swati
  • 28,069
  • 4
  • 21
  • 41
  • @JustaNewProgrammer check https://stackoverflow.com/questions/2889871/how-do-i-escape-reserved-words-used-as-column-names-mysql-create-table – seenukarthi Feb 04 '20 at 07:19
0

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

ScarySpider
  • 139
  • 5