we have used executeQuery()
for deleting the data in a table using java code.It is able to delete properly when we run the program using Eclipse, but while build the sources and deployed in glassfish server am getting error.
java.sql.SQLException: SQL string is not Query
Means, we should not use executeQuery()
for DML operations.If that is the case it should not even work in eclipse.
Below is my code:
PreparedStatement deletePreparedStmt = null;
String sql = "DELETE FROM emp WHERE eno = ?";
try
{
deletePreparedStmt = con.prepareStatement(sql);
deletePreparedStmt.setInt(1,50);
deletePreparedStmt.executeQuery();
con.commit();
}
catch(Exception e)
{
e.printStackTrace();
}
Can anyone clarify it?