Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.55 KB | None | 0 0
  1. package me.creepercow.DBTL.account;
  2.  
  3. import me.creepercow.DBTL.Main;
  4. import org.bukkit.configuration.file.FileConfiguration;
  5. import org.bukkit.plugin.Plugin;
  6.  
  7. import java.io.File;
  8. import java.sql.*;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11.  
  12. public class Utils {
  13.     private static Plugin plugin = new Main();
  14.  
  15.     @SuppressWarnings("unused")
  16.     static File dataFile;
  17.     static FileConfiguration data;
  18.     public static void Setup() {
  19.         Logger logger = Logger.getLogger("Minecraft");
  20.         String url = "jdbc:sqlite:" + plugin.getDataFolder().getAbsolutePath() + File.separatorChar + "Data";
  21.         String table_account = "CREATE TABLE IF NOT EXISTS accounts (\n"
  22.                 + " id interger PRIMARY KEY,\n"
  23.                 + " name text NOT NULL INDEX, \n"
  24.                 + " blood interger DEFAULT 0, \n"
  25.                 + " shards interger DEFAULT 0, \n"
  26.                 + " rank text NOT NULL, \n"
  27.                 + " passes interger, \n"
  28.                 + " );";
  29.         String table_server = "CREATE TABLE IF NOT EXISTS server (\n"
  30.                 + " Shrine1 text, \n"
  31.                 + " Shrine2 text, \n"
  32.                 + " Shrine3 text, \n"
  33.                 + " Shrine4 text, \n"
  34.                 + " DoubleXP boolean, \n"
  35.                 + " DoubleBlood boolean, \n"
  36.                 //+ " "
  37.                 + " );";
  38.         try (Connection conn = DriverManager.getConnection(url)) {
  39.             if (conn != null) {
  40.                 DatabaseMetaData meta = conn.getMetaData();
  41.                 logger.info("Database created");
  42.                 Statement stmt = conn.createStatement();
  43.                 stmt.execute(table_account);
  44.                 stmt.execute(table_server);
  45.             }
  46.         } catch (SQLException e) {
  47.             logger.log(Level.SEVERE, e.getMessage());
  48.         }
  49.  
  50.     }
  51.  
  52.     public static Connection Connect() {
  53.         Logger logger = Logger.getLogger("Minecraft");
  54.         String url = "jdbc:sqlite:" + plugin.getDataFolder().getAbsolutePath() + File.separatorChar + "Data";
  55.         try (Connection conn = DriverManager.getConnection(url)) {
  56.             return conn;
  57.         } catch (SQLException e) {
  58.             logger.log(Level.SEVERE, e.getMessage());
  59.         }
  60.         return null;
  61.     }
  62.  
  63.     public void CreatePlayer(String name) throws SQLException {
  64.         String sql = "INSERT INTO accounts(name,rank) VALUES(" + name + ",DEFAULT)";
  65.         Connection conn = Connect();
  66.         Statement stmt = conn.createStatement();
  67.         stmt.executeQuery(sql);
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement