-2

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?

sravani reddy
  • 45
  • 1
  • 2
  • 9

1 Answers1

0

GlassFish server internally having ojdbc7dms.jar, which is not allowing executeQuery() method for DML operations. Because of that only we are getting

java.sql.SQLException: SQL string is not Query Exception

sravani reddy
  • 45
  • 1
  • 2
  • 9