tags:

views:

255

answers:

4

in mysql i have two tables

tableA

col1   col2  SIM1 ..........col24
a       x     1             5 
b       y     1             3
c       z     0             2
d       g     2             1

tableB

colA   colB   SIM2
x       g     1
y       f     0
x       s     0
y       e     2

i am using java program to connect to mysql database using jdbc. i need to index with columns sim1 and sim2

String query1 = " create index on TableA (SIM1) ";
String query2 = " create index on TableB (SIM2) ";

i am trying to execute the two queryies using

executeQuery(query1) and executeQuery(query2) but i get the error

can not issue data manipulation statements with executeQuery().

what can i do ?

+1  A: 

To manipulate data you actually need executeUpdate() rather than executeQuery().

Here's an extract from the executeUpdate() javadoc which is already an answer at its own:

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

BalusC
A: 

That's what executeUpdate is for.

Here's a very brief summary of the difference: http://www.coderanch.com/t/301594/JDBC/java/Difference-between-execute-executeQuery-executeUpdate

Carl Smotricz
A: 

ExecuteQuery expects a result set. I'm not as familiar with Java/MySQL, but to create indexes you probably want a ExecuteUpdate().

Neil N
It does not expect a `ResultSet`. It instead **returns** a `ResultSet`.
BalusC
It expects a result set from the DB is what I mean.
Neil N
+1  A: 

Use executeUpdate() to issue data manipulation statements. executeQuery() is only meant for SELECT queries (i.e. queries that return a result set).

OMG Ponies