开发者

Java PreparedStatement and Alter Table syntax error

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.prepareState开发者_开发问答ment("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


You've forgotten a space before the "ADD".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜