gpt4 book ai didi

java - 找不到 SQL 更新语句中的错误

转载 作者:行者123 更新时间:2023-12-01 16:44:29 24 4
gpt4 key购买 nike

我正在开发一款问答游戏。有提问者窗口。这对于保存问题很有用。但是,当想要更新文本字段之一并按保存时,就会发生错误。语法有问题吗?!

void insertCell(String tableNamer, String column, String value, int id) throws ClassNotFoundException, SQLException{
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:file:C:/Users/Juris Puneiko/IdeaProjects/for_my_testings/src/sample/DB/Questions/For_Private/Easy", "Juris", "1");

PreparedStatement ps = conn.prepareStatement("UPDATE ? SET ? = ? where ID = ?");
ps.setString(1, tableNamer);
ps.setString(2, column);
ps.setString(3, value);
ps.setInt(4, id);
ps.executeUpdate();
ps.close();
conn.close();
}

org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "UPDATE ?[*] SET ? = ? WHERE ID = ? "; expected "identifier"; SQL statement: UPDATE ? SET ? = ? where ID = ? [42001-196]

这是什么>>> [*]?

这是什么意思?

Screenshot

最佳答案

String sql = "UPDATE " + tableNamer + " SET " + column + " = ? where  ID = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, value);
ps.setInt(2, id);
ps.executeUpdate();
ps.close();
conn.close();

关于java - 找不到 SQL 更新语句中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55040454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com