I'm new to java, i want to update my database table columns. but when running this code I'm getting this error.
execom.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 'Mcgreth' at line 1
I tried for 1 week. but I cant even think where's the wrong. plzz help me.. thanks a lot for help.this is my code.
public boolean update(File2nd dt) {
try {
con = (Connection) DriverManager.getConnection(url, username, password);//get the connection
String query = "UPDATE file1 SET name='" + dt.getName()+ "',age='" + dt.getAge()+ "',color="+dt.getColor()+ ""
+ " WHERE name=" + dt.getName();
pst = (com.mysql.jdbc.PreparedStatement) con.prepareStatement(query);
pst.executeUpdate();
System.out.println("Updated queries: ");
return true;
} catch (Exception e) {
System.out.println("exe" + e);
return false;
} finally {
try {
if (pst != null) {
pst.close();
}
if (con != null) {
con.close();
}
} catch (Exception e) {
}
}
}