Advertisement
Guest User

MySQL - Config

a guest
Aug 2nd, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. package mpack;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8.  
  9. public class MySQL {
  10.     public static String host = "snapecrafter.bplaced.net";
  11.     public static String port = "3306";
  12.     public static String database = "snapecrafter";
  13.     public static String username = "snapecrafter";
  14.     public static String password = "*************";
  15.     public static Connection con;
  16.    
  17.     public static void connect() {
  18.         if(!isConnected()) {
  19.             try {
  20.                 con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database,username,password);
  21.                 System.out.println("[MySQL] Verbindung aufgebaut!");
  22.             } catch (SQLException e) {
  23.                 // TODO Auto-generated catch block
  24.                 e.printStackTrace();
  25.             }
  26.         }
  27.     }
  28.     public static void disconnect() {
  29.         if(isConnected()) {
  30.             try {
  31.                 con.close();
  32.                 System.out.println("[MySQL] Verbindung geschlossen!");
  33.             } catch (SQLException e) {
  34.                 // TODO Auto-generated catch block
  35.                 e.printStackTrace();
  36.             }
  37.         }
  38.     }
  39.     public static boolean isConnected() {
  40.         return (con == null ? false : true);
  41.     }
  42.     public static void update(String qry) {
  43.         try {
  44.             PreparedStatement ps = con.prepareStatement(qry);
  45.             ps.executeUpdate();
  46.         } catch (SQLException e) {
  47.             // TODO Auto-generated catch block
  48.             e.printStackTrace();
  49.         }
  50.     }
  51.     public static ResultSet getResult(String qry) {
  52.         PreparedStatement ps;
  53.         try {
  54.             ps = con.prepareStatement(qry);
  55.             return ps.executeQuery();
  56.         } catch (SQLException e) {
  57.             // TODO Auto-generated catch block
  58.             e.printStackTrace();
  59.         }
  60.         return null;
  61.        
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement