Code: Select all
queryL=
"SELECT RATING"
+ " FROM USERS"
+ " WHERE UUID = '"
+ UUID +"';";
queryG=
"SELECT RATING"
+ " FROM " + Constants.serverName
+ "_USERS"
+ " WHERE UUID = '"
+ UUID +"';";
try {
stmt=con.createStatement();
rs=stmt.executeQuery(queryL);
if (rs.next()){
r.setLocalRating(rs.getInt(1));
}else{
r.setLocalRating(0);
registerPlayer(UUID,false);
Dungeon.getPlugin(Dungeon.class).log("Player new to server");
}
stmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try{
stmt=con.createStatement();
rs=stmt.executeQuery(queryG);
if (rs.next()){
r.setGlobalRating(rs.getInt(1));
}else{
r.setGlobalRating(0);
registerPlayer(UUID,true);
Dungeon.getPlugin(Dungeon.class).log("Player new to network");
}
stmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Der folgende Code zeigt die Aktualisierungsabfragen, die in der Methode „registerPlayer“ verwendet werden.
Code: Select all
if (global){
query=
"INSERT INTO"
//+ Constants.dbName + "."
+ " USERS"
+ " VALUES ('"
+ UUID + "', 0)";
}else{
query=
"INSERT INTO "
//+ Constants.dbName + "."
+ Constants.serverName
+ "_USERS "
+ "VALUES ('"
+ UUID + "', 0)";
}
Code: Select all
String userLocalTable=
"CREATE TABLE IF NOT EXISTS " //+ Constants.dbName + "."
+ Constants.serverName +
"_USERS " +
"(UUID varchar(36) NOT NULL, " +
"RATING int NOT NULL, " +
"PRIMARY KEY (UUID))";
String userGlobalTable=
"CREATE TABLE IF NOT EXISTS " + //Constants.dbName + "."
"USERS " +
"(UUID varchar(36) NOT NULL, " +
"RATING int NOT NULL, " +
"PRIMARY KEY (UUID))";
Mobile version