Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9197
  • Last Modified:

java.sql.SQLException: Can not issue data manipulation statements with executeQuery().

I've just change from MM.MySQL to connectors/j  .

Connection and request to the database is working fine
but, my DELETE statements are not working anymore.


         String deleteProgramExecution = "DELETE FROM program_execution WHERE user_id="+userID;

         ValueSet vs3 = DB.requestPrepared(deleteProgramExecution);
         vs3.execute();
         vs3 = null;

//-----------------------------
In DB (Data class)

      public ValueSet requestPrepared(String sqlString) {
            return new ValueSet(sqlString, true);
      }

//----------------------------------
      public class ValueSet {
            private Statement sqlStmt;
            private ResultSet set;

                                public ValueSet(String sqlString, boolean prepare) {
                  if (prepare) {
                        try {
                              sqlStmt = c.prepareStatement(sqlString);
                        } catch (Exception e) {
                              e.printStackTrace();
                        }
                  }
            }

            public void execute() {
                  try {
                        set = ((PreparedStatement)sqlStmt).executeQuery();
                  } catch (Exception e) {
                        e.printStackTrace();
                  }
            }

//  more code....
0
SolangeRichard
Asked:
SolangeRichard
  • 3
  • 2
1 Solution
 
hoomanvCommented:
insetead of executeQuery use executeUpdate
0
 
SolangeRichardAuthor Commented:
but executeQuery returns a ResultSet and executeUpdate returns a int...
0
 
hoomanvCommented:
you can not alter table using executeQuery
if you want the ResultSet either use new Jdbc APIs like UpdatableResultSets or
first do alterations and then query the table to give you the new results
0
 
SolangeRichardAuthor Commented:
ah oupsss. my error again.  
I will stop asking questions here for today I guess I'm just too tired *smile*.

I was indeed using executeQuery instead of executeUpdate!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now