Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MySQL {
- public static String user = "user";
- public static String pass = "password";
- public static String host = "localhost";
- public static String db = "db";
- public static int port = 3306;
- public static Connection con;
- public static void connect() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + db + "?autoReconnect=true", user, pass);
- System.out.println("[NexusCore]MySQL > Verbindung hergestellt!");
- }
- catch (ClassNotFoundException | SQLException e) {
- System.out.println("[NexusCore]MySQL > Konnte keine Verbindung aufbauen!");
- }
- }
- public static void close() {
- if (con != null) {
- try {
- con.close();
- System.out.println("[NexusCore]MySQL > Verbindung geschlossen!");
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void update(String qry) {
- if (con != null) {
- try {
- Statement stmt = con.createStatement();
- stmt.executeUpdate(qry);
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- } else {
- System.out.println("[NexusCore]MySQL > Es besteht keine Verbindung!");
- }
- }
- public static ResultSet query(String qry) {
- ResultSet rs = null;
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(qry);
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- return rs;
- }
- public static void reconnect() {
- MySQL.close();
- MySQL.connect();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement