I'm using a preparedStatement in Java to update and replace records in a MSSQL 2008 database as follows:
ps = settings.conn.prepareStatement("UPDATE table SET ? = replace((?), (?), (?)) ");
I am then passing in the arguments as follows:
String[] columns= {"a", "b", "c", "d"};
for (int i = 0; i < columns.length; i++) {
ps.setString(1, columns[i]);
ps.setString(2, columns[i]);
ps.setString(3, " " + oldName.trim() + " ");
ps.setString(4, " " + newName.trim() + " ");
ps.addBatch();
batchSize++;
if (batchSize > 5000) {
batchSize = 0;
ps.executeBatch();
}
}
I get a lot of error messages saying incorrect syntax near @po. From this question I understand that the Top-statement should be inclosed in brackets when it is used in a parameterized statement.
Could it be that the Update statement also needs some additional formatting before I can use it? Or is something else going wrong?