gpt4 book ai didi

java - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException | JAVA

转载 作者:太空宇宙 更新时间:2023-11-03 12:14:13 24 4
gpt4 key购买 nike

我想在我的 java 项目中获取表中的条目数。

这是我的代码:

int count = 0;
Statement st = Mysql.con.createStatement();
ResultSet rs= st.executeQuery("select count(*) from keys where spieler =" +p.getName());
while (rs.next()){
count = rs.getInt(1);
}

我得到以下 SQLEXCEPTION:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near 'keys where spieler =Pit910' at line 1

什么是磨损?

谢谢!

最佳答案

keys 是一个 reserved MySQL keyword需要转义(那个或 ALTER 表以给它一个不同的名称)。试试这个

PreparedStatement preparedStatement = 
con.prepareStatement("select count(*) from `keys` where spieler = ?");
preparedStatement.setString(1, p.getName());
ResultSet rs= preparedStatement.executeQuery();
...

关于java - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException | JAVA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22893151/

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