Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.socialgames.common_db;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import net.socialgames.common_db.Connection;
- public class Credits {
- private static Table table;
- public static void initialize() {
- if(!Connection.isOpen()) {
- System.out.println("(CREDITS) Could not initialize: Database is not open yet");
- return;
- }
- if(!Connection.existsTable("credits")) {
- Connection.createTable("credits",
- new String[]{
- "uuid varchar(60) NOT NULL UNIQUE",
- "credits int default 0",
- "primary key (uuid)"
- }
- );
- }
- System.out.println("(CREDITS) Initialized successfully");
- }
- protected static int get(String uuid) {
- try {
- ResultSet res = table.select(new String[] { "credits" }, "uuid = \"" + uuid + "\"");
- if (res == null || !res.next()) {
- // Either error or no language preference
- return 0;
- }
- return res.getInt("credits");
- } catch (SQLException e) {
- System.out.println("Could not get credits for " + uuid);
- e.printStackTrace();
- return -1;
- }
- }
- protected static void save(String uuid, int credits) {
- try {
- table.insert(new String[] { "uuid", "credits" }, new String[] { "\"" + uuid + "\"", Integer.toString(credits) },
- "credits=" + Integer.toString(credits) // On duplicate
- );
- } catch (SQLException e) {
- System.out.println("Could not save credits for " + uuid);
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement