I have to create an index on a field of a table using PreparedStatement. The query that I've to perform is the following:
ALTER TABLE esa_matrix ADD INDEX doc_index (id_doc)
So, I've create a PreparedStatement instance with the same text of the query and perform executeUpdate() method on it. But at execution time I get a SQL syntax error.
This is creation of the PreparedStatement instance:
PreparedStatement ps = conn.prepareStatement("ALTER TABLE "+ESATable+ "ADD INDEX doc_index ("+idDocLabel+")");
ps.executeUpdate();
ps.close();
This SQLException I get:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'doc_index (id_doc)' at line 1
How can I solve this?
Thanks in advance,
Antonio
String query = String.format("ALTER TABLE %s ADD INDEX doc_index (%s)", ESATable, idDocLabel);