Reputation: 7386
I wrote the following method to execute update statement inside the database:
public boolean updateEmployee(int id){
try {
String update="UPDATE employee set name='updatedName' and address='updatedaddress' where id=(?)";
pst=connection.prepareStatement(update);
pst.setInt(1, id);
pst.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
return true;
}
But the following exception occurs:
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
And this exception is also thrown:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'UpdatedName'
What's the problem here? In addition, how can I return the result of an update statement (since executeQuery
doesn't work with DML Statements)?
Upvotes: 2
Views: 612
Reputation: 393771
I might be wrong, but perhaps the statement should be
UPDATE employee set name='updatedName' , address='updatedaddress' where id=(?)
instead of
UPDATE employee set name='updatedName' and address='updatedaddress' where id=(?)
and
should be used only in the where clause.
Upvotes: 2
Reputation: 272217
Looks like an unclosed quote issue ?
name='updatedname and address
Upvotes: 5