Nathaniel Brown Nathaniel Brown - 1 year ago 72
MySQL Question

Why am I receiving a MySQLSyntaxErrorException

I receive this 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

I have looked up the reference manual for the MySQL syntax but I'm not exactly sure what I'm looking for there.

Here is my code:

try {
Connection myC = DriverManager.getConnection("jdbc:mysql://localhost:3306/sakila?autoReconnect=true&useSSL=false", "root", "George18");

Statement myS = myC.createStatement();

//Insert in to database
String sqlUp = "INSERT into actor (actor_id, first_name, last_name, last_update) values(97241, 'Test', 'Name', '7:02:34'";

System.out.println("Insert complete");

//Update the database
myS.executeUpdate("UPDATE actor"
+ " set last_name='Changed'"
+ " where actor_id=1");

System.out.println("Update complete");

/*int rowsAffected = myS.executeUpdate("DELETE from actor"
+ " where last_name='Changed'");


} catch(Exception ex) {


Answer Source

U missed to close values()

String sqlUp = "INSERT into actor (actor_id, first_name, last_name, last_update) values(97241, 'Test', 'Name', '7:02:34')";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download