For some reason I'm not able to update my database using this code. Can someone help me out? What I've got is when a player completes a certain task it records the time it took them if and only if their time is lower than the best recorded time.
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.");
}
}
Aucun commentaire :
Enregistrer un commentaire