Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.jlpcrew.lobbyscoreboard;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.UUID;
- public class MySQLPunkte {
- public static boolean isUserExists(UUID uuid) {
- try {
- PreparedStatement st = MySQL.con.prepareStatement("SELECT Punkte FROM PunkteSystem WHERE UUID = ?");
- st.setString(1, uuid.toString());
- ResultSet rs = st.executeQuery();
- return rs.next();
- } catch(SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public static int getPoints(UUID uuid) {
- try {
- PreparedStatement st = MySQL.con.prepareStatement("SELECT Punkte FROM PunkteSystem WHERE UUID = ?");
- st.setString(1, uuid.toString());
- ResultSet rs = st.executeQuery();
- while (rs.next()) {
- return rs.getInt("Punkte");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return -1;
- }
- public static void setPoints(UUID uuid, int points) {
- if(getPoints(uuid) == -1) {
- try {
- PreparedStatement st = MySQL.con.prepareStatement("INSERT INTO PunkteSystem (UUID,Punkte) VALUES (?,?)");
- st.setString(1, uuid.toString());
- st.setInt(2, points);
- st.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- } else {
- try {
- PreparedStatement st = MySQL.con.prepareStatement("UPDATE PunkteSystem set Punkte = ? WHERE UUID = ?");
- st.setString(2, uuid.toString());
- st.setInt(1, points);
- st.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void addPoints(UUID uuid, int points) {
- int current = getPoints(uuid);
- setPoints(uuid, points + current);
- }
- public static void removePoints(UUID uuid, int points) {
- int current = getPoints(uuid);
- setPoints(uuid, current - points);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement