I surf the net and don't search what I need. So please you help me. When I try to execute this SQL statement in Eclipse
private final String INSERT_ = "INSERT INTO department VALUES (?, ?, ?)";
I have next error: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 This is my code
public void insert(int id, String name, String description) throws SQLException
{
Department result = null;
Connection conn = ConnectionManager.getConnection();
PreparedStatement stmt = conn.prepareStatement(INSERT_);
stmt.setInt(1, id);
stmt.setString(2, name);
stmt.setString(3, description);
stmt.executeUpdate(INSERT_);
System.out.println("Record is inserted into table!");
}
Thanks in advance!
You shouldn't pass the SQL String to executeUpdate
, since your PreparedStatement
was already initialized with the SQL String + the parameters.
Change
stmt.executeUpdate(INSERT_);
to
stmt.executeUpdate();
enter image description here this is my opinion,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.