Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String HOST = "localhost";
- public static String DATABASE = "Lobby2";
- public static String USER = "root";
- public static String PASSWORD = "localhost1P2";
- private static Connection con;
- public Connector(String host, String database, String user, String password)
- {
- HOST = host;
- DATABASE = database;
- USER = user;
- PASSWORD = password;
- connect();
- }
- public void connect()
- {
- try
- {
- this.con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true", USER, PASSWORD);
- System.out.println(ChatColor.DARK_GREEN + "[BungeeSystem] Die Verbindung mit der MySQL Datenbank wurde hergestellt");
- }
- catch (SQLException e)
- {
- System.out.println(ChatColor.RED + "[BungeeSystem] Es konnte keine Verbindung zur MySQL Datenbank hergestellt werden es ist folgender Fehler aufgetreten: " + e.getMessage());
- }
- }
- public void close()
- {
- try
- {
- if (this.con != null) {
- this.con.close();
- }
- }
- catch (SQLException localSQLException) {}
- }
- public void update(String qry)
- {
- try
- {
- Statement st = this.con.createStatement();
- st.executeUpdate(qry);
- st.close();
- }
- catch (SQLException e)
- {
- connect();
- System.err.println(e);
- }
- }
- public ResultSet query(String qry)
- {
- ResultSet rs = null;
- try
- {
- Statement st = this.con.createStatement();
- rs = st.executeQuery(qry);
- }
- catch (SQLException e)
- {
- connect();
- System.err.println(e);
- }
- return rs;
- }
- public static Connection getConnection()
- {
- return con;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement