Java PreparedStatement reclamando da sintaxe SQL em execute ()
Isto está me deixando louco ... O que estou fazendo de errado aqu
ArrayList<String> toAdd = new ArrayList<String>();
toAdd.add("password");
try{
PreparedStatement pStmt = conn.prepareStatement("ALTER TABLE testTable ADD ? varchar(100)");
for (String s : toAdd) {
pStmt.setString(1, s);
pStmt.execute();
}
} catch (SQLException e) {
e.printStackTrace();
}
Resulta em..
02: 59: 12,885 ERRO [STDERR] com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: você tem um erro na sintaxe do SQL; verifique o manual que corresponde à versão do servidor MySQL para a sintaxe correta a ser usada perto de '' password 'varchar (100)' na linha 1
mas..
ArrayList<String> toAdd = new ArrayList<String>();
toAdd.add("password");
try{
Statement stmt = conn.prepareStatement();
for (String s : toAdd) {
stmt.execute("ALTER TABLE testTable ADD "+s+" varchar(100)");
}
} catch (SQLException e) {
e.printStackTrace();
}
funciona perfeitamente ... O mesmo ocorre com a inserção direta do texto diretamente no cliente de linha de comando do MySQ
mysql> alter table testTable add stringGoesHere varchar(100);
Query OK, 1 row affected (0.23 sec)
Records: 1 Duplicates: 0 Warnings: 0
O que estou fazendo errado