Details of table under consideration :
Code used for updating rows is :
public void updateEmployeeDetails(Employee employee) {
Connection conn = JDBCUtility.getConnection();
try {
String updateSql = "UPDATE EMPLOYEE_INFO SET emp_name=?, location=?, email=?, dob=? WHERE emp_id=?";
PreparedStatement ps = (PreparedStatement)conn.prepareStatement(updateSql);
ps.setString(1, employee.getEmp_name()); /*all the attributes of employee object are of type String */
ps.setString(2, employee.getLocation());
ps.setString(3, employee.getEmail());
ps.setString(4, employee.getDob());
ps.setString(5, employee.getEmp_id());
ps.executeUpdate(updateSql);
} catch (SQLException e) {
System.out.println(e.getErrorCode());
e.printStackTrace();
}
}
Error Received :
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 '?, location=?, email=?, dob=? WHERE emp_id=?' at line 1
Can anyone point out the error because I doubly checked any possible error in my query string? Is varchar(45)
of mysql compatible with Java's String
? i.e. could ps.setString(column_index, String)
be the root cause of error?
DEBUG 1 :
Considering null
possibility I tried(in vain) following :
// ps.setString(1, employee.getEmp_name());
// ps.setString(2, employee.getLocation());
// ps.setString(3, employee.getEmail());
// ps.setString(4, employee.getDob());
// ps.setString(5, employee.getEmp_id());
ps.setString(1, "Superman");
ps.setString(2, "Sky");
ps.setString(3, "anymail@dooodle.com");
ps.setString(4, "1-1-0111");
ps.setString(5, "501");
ps.executeUpdate(updateSql);
but still the same output is shown .