Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static File file = new File("plugins//KnockOUT//mySQL//mySQL.yml");
- public static YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- private static String HOST = cfg.getString("mySQL.Host");
- private static String DATABASE = cfg.getString("mySQL.Database");
- private static String USER = cfg.getString("mySQL.User");
- private static String PASSWORD = cfg.getString("mySQL.Password");
- private static Connection con;
- public mySQL(String host, String database, String user, String password) {
- mySQL.HOST = host;
- mySQL.DATABASE = database;
- mySQL.USER = user;
- mySQL.PASSWORD = password;
- connect();
- }
- public static void connect() {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true",
- USER, PASSWORD);
- System.out.println("[MySQL] Die Verbindung zur MySQL wurde hergestellt!");
- } catch (SQLException e) {
- System.out.println("[MySQL] Die Verbindung zur MySQL ist fehlgeschlagen! Fehler: " + e.getMessage());
- }
- }
- public void close() {
- try {
- if (con != null) {
- con.close();
- System.out.println("[MySQL] Die Verbindung zur MySQL wurde Erfolgreich beendet!");
- }
- } catch (SQLException e) {
- System.out.println("[MySQL] Fehler beim beenden der Verbindung zur MySQL! Fehler: " + e.getMessage());
- }
- }
- public static void update(String qry) {
- try {
- Statement st = con.createStatement();
- st.executeUpdate(qry);
- st.close();
- } catch (SQLException e) {
- connect();
- System.err.println(e);
- }
- }
- public static ResultSet query(String qry) {
- ResultSet rs = null;
- try {
- Statement st = con.createStatement();
- rs = st.executeQuery(qry);
- } catch (SQLException e) {
- connect();
- System.err.println(e);
- }
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement