java - SQL WHERE 不适用于 Discord
问题描述
所以我得到一个数据库,我的不和谐机器人正在连接到数据库,但是当我得到它时,我得到一个错误 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'd1aa852e1a504d6cafbd55e0d2d28dea' in 'where clause' 这是我的代码
int id = SQLUser.getIntFromDatabase("SELECT * FROM Players WHERE UUID = " + uuid.toString() + "", "ID");
if(id==-1) channel.sendMessage("ID is not valid please login to the WidowMC").queue();
else
{
Message messa = new MessageBuilder().append(Utils.getName(uuid) + " Skull").build();
channel.sendFile(Utils.getSkullFile(Utils.getName(uuid)), messa).queue();
channel.sendMessage("ID = " + id);
}
public static void excuteQuery(String query)
{
Connection conn = Core.getConnection();
try
{
Statement statement = conn.createStatement();
statement.executeQuery(query);
} catch (SQLException e)
{
e.printStackTrace();
}
}
解决方案
您需要在 uuid 周围添加引号以使其成为文字,否则 Mysql 认为您指的是列。
另外要非常小心,您的代码容易受到 SQL 注入的影响,正确使用Prepared Stamements可以帮助您消除该漏洞。
推荐阅读
- partitioning - 想要更多地控制 ReplicatedMergeTree 部分在 clickhouse 中的合并
- python-3.x - PyAutoGUI 无法检测到视频下的 FB 批准按钮,但它与照片下的按钮配合良好。有什么建议么?
- sed - 在 Lua 脚本上运行 sed 命令
- react-native - 反应原生 | 设置状态的函数
- powerbi - DAX 无法比较文本和整数,但没有参考列是文本
- amazon-web-services - 如何根据 Grafana 中另一个变量的选择来填充一个变量?
- ruby-on-rails - 在 Rails_Admin 中显示 ActiveStorage 映像
- parse-platform - 使用 REST API 获取多对多关系项
- java - Android UnitTest 中的 Application.class 模拟
- linux - 如何将参数(中间包含空格)从 UNIX 中每一行的文本文件传递给 shell 脚本?