gpt4 book ai didi

java - MySQL 不执行 (Java)

转载 作者:行者123 更新时间:2023-11-30 22:41:09 25 4
gpt4 key购买 nike

出于某种原因,我无法使用此代码更新我的数据库。有人可以帮我吗?我得到的是,当玩家完成某项任务时,当且仅当他们的时间低于最佳记录时间时,它才会记录他们花费的时间。

    public void setScores(MapleCharacter chr, int mapid, float time) {
Connection con1 = DatabaseConnection.getConnection();
try {
PreparedStatement ps;
ps = con1.prepareStatement("SELECT time from jumpquests WHERE characterid = ? AND mapid = ?");
ps.setInt(1, chr.getId());
ps.setInt(2, chr.getMapId());
ResultSet rs = ps.executeQuery();
if (rs.next()) {
if (time < rs.getFloat("time")) {
executeScores(chr, mapid, time);
}
} else {
executeScores(chr, mapid, time);
}
rs.close();
ps.close();
} catch (Exception Ex) {
System.out.println("Ran into exception.");
}
}

public void executeScores(MapleCharacter chr, int mapid, float time) {
System.out.println("Setting scores for " + chr.getName() + " for map " + mapid + " at time " + time);
Connection con1 = DatabaseConnection.getConnection();
try {
PreparedStatement ps = con1.prepareStatement("REPLACE INTO jumpquests (characterid, mapid, time) values (?,?,?)");
ps.setInt(1, chr.getId());
ps.setInt(2, chr.getMapId());
ps.setFloat(3, time);
ps.close();
} catch (Exception e) {
System.out.println("Executing scores ran into exception.");
}
}

最佳答案

我不确定与 JAVA 相关的任何内容,但您的 REPLACE INTO SQL 语句包含保留字 time,需要使用 backtique 进行转义,例如以下。参见 MySQL Documentation获取更多信息。

REPLACE INTO jumpquests (characterid, mapid, time) values (?,?,?)
^........Here

应该是

REPLACE INTO jumpquests (characterid, mapid, `time`) values (?,?,?)

关于java - MySQL 不执行 (Java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31125714/

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