Java PreparedStatement complaining about SQL syntax on execute()

前端 未结 6 1826
梦毁少年i
梦毁少年i 2020-12-21 06:20

This is driving me nuts... What am I doing wrong here?

ArrayList toAdd = new ArrayList();
toAdd.add(\"password\");
try{
    Prepa         


        
6条回答
  •  有刺的猬
    2020-12-21 06:59

    When using a prepared statement, your parameter is treated similarily to a string literal. As a result, your statement is equivalent to "ALTER TABLE testTable ADD \'"+s+"\' varchar(100)". Notice the single quotations around the field name in the error message.

    I would suggest building a literal statement in this case, and not attempting to used a prepared statement.

提交回复
热议问题