Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String username = "root";
- public static String pass = "";
- public static String database = "FutoraMC";
- public static String host = "localhost";
- public static Connection con;
- public static void connect(){
- try {
- con = DriverManager.getConnection("jdbc:mysql://"+host+":3306"+"/"+database, username, pass);
- BungeeCord.getInstance().getConsole().sendMessage("§f[§eMySQL§f] §aConnected");
- createTable();
- } catch (SQLException e) {
- e.printStackTrace();
- Bukkit.getConsoleSender().sendMessage("§f[§eMySQL§f] §cError while connecting");
- }
- }
- public static void close(){
- if(!isConnected()){
- try {
- con.close();
- Bukkit.getConsoleSender().sendMessage("§f[§eMySQL§f] §cDisconnected");
- } catch (SQLException e) {
- e.printStackTrace();
- Bukkit.getConsoleSender().sendMessage("§f[§eMySQL§f] §cError while disconnecting");
- }
- }
- }
- public static boolean isConnected(){
- return con != null;
- }
- public static void createTable(){
- if(isConnected()){
- try {
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS PlayerInfo (Spielername VARCHAR(100), " +
- "JoinMe INTEGER(100))");
- Bukkit.getConsoleSender().sendMessage("§f[§eMySQL§f] §6Tabellen erstellt, sofern noch nicht vorhanden");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void update(String qry){
- if(isConnected()){
- try {
- con.createStatement().executeUpdate(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static ResultSet getResult(String qry){
- if(isConnected()){
- try {
- return con.createStatement().executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement