• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with com.mysql.jdbc.exceptions.MySQLSyntaxErrorException

 
Ertan Hasani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys , im trying to add some datas to my database , but it appears an error: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException .

Here's the code:

AddToDatabase Method in Main.java


AddNewEmployeeController.java


OUTPUT:


p.s. Main:java:58 is this row :


AddNewEmployeeController.java:164 is this row:


Years,Single,Male,1404996,Electrical,Design,Yes is:
when i tried to add data to : TextField ageField, ChoiceBox martialStatusBox,"Male", idField, ComboBox mainDepartmentBox, ComboBox departmentBox,"Yes".
 
Dave Tolls
Ranch Hand
Posts: 2095
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you print out your SQL statement you'll see that it is missing quote marks around the text data.
The best way to avoid this issue is to use a PreparedStatement and assign the variables using the setXXX (eg setString) methods.

Here's the tutorial page on PreparedStatements:
https://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html
 
Ertan Hasani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:If you print out your SQL statement you'll see that it is missing quote marks around the text data.
The best way to avoid this issue is to use a PreparedStatement and assign the variables using the setXXX (eg setString) methods.

Here's the tutorial page on PreparedStatements:
https://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html


Thank you so much , now it works fine with PreparedStatement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic