1

我的 java/jdbc 代码有问题。

参数索引超出范围(2 个参数,即 1)

代码:

                Connection c = null;
                MySQL MySQL = new MySQL(Host, Port, Database, Username, Password);
                c = MySQL.open();  
              Player player = (Player) sender;
               String zapytanie = "UPDATE `?` SET `tag`=? WHERE   `name`='?';";
               PreparedStatement ps = c.prepareStatement( zapytanie );
               ps.setString(1, Tabel);
               ps.setString(2, red);
               ps.setString(3, player());
               ps.executeUpdate(); //Executes the query
               ps.close(); //Closes the query
               c.close();
4

1 回答 1

4
final String zapytanie = "UPDATE " + Table + " SET tag = ? WHERE name = ?";
  • ?不需要引号
  • JDBC 不需要任何SQL 语句;之后
  • 占位符?只能用于列值
于 2013-06-24T17:15:32.303 回答