In many programming languages, something like this is possible for prepared statements:
PreparedStatement statement = connection.prepareStatement( "SELECT id FROM Company WHERE name LIKE ${name}"); statement.setString("name", "IBM");
But not with java.sql.PreparedStatement. In Java, you need to use parameter indices:
PreparedStatement statement = connection.prepareStatement( "SELECT id FROM Company WHERE name LIKE ?"); statement.setString(1, "IBM");
Is there a solution for working with string variables, as in the first example? Is "$ {. *}" Not to be used elsewhere in SQL or conflicts? Because then I would implement it myself (parsing the SQL string and replacing each variable with "?", And then executing that Java path).
Regards, Kai
java jdbc
Zardoz Jul 08 '09 at 12:48 2009-07-08 12:48
source share