Issue
I'm getting the following error :
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '' at line 1.
While trying to run the following code:
String sql = "INSERT INTO `tutors`.`appointments`"
+ "(`tutorID`, `tuteeName`, `tuteeEmail`, `time`, `date`)"
+ ("VALUES(?, ?, ?, ?, ?");
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, working.get(0).getTutorID());
ps.setString(2, tuteeName);
ps.setString(3, tuteeEmail);
ps.setDate(4, date);
ps.setTime(5, time);
ps.executeUpdate();
What is it producing the ' '
that the exception is referring to? I'm just learning to work with SQL in java, so I'm sure this is just a silly syntactical error...
Solution
You were not closing the VALUES parenthesis:
String sql = "INSERT INTO `tutors`.`appointments`"
+ " (`tutorID`, `tuteeName`, `tuteeEmail`, `time`, `date`)"
+ ("VALUES(?, ?, ?, ?, ?)");
Answered By - Asaf