Just a New Programmer
Just a New Programmer

Reputation: 59

java.sql.SQLSyntaxErrorException:

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

Upvotes: 3

Views: 526

Answers (2)

ScarySpider
ScarySpider

Reputation: 137

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

Upvotes: 0

Swati
Swati

Reputation: 28522

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 .

Upvotes: 12

Related Questions