Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MySQL;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class MySQL {
- public static String username;
- public static String password;
- public static String database;
- public static String host;
- public static String port;
- public static Connection con;
- public static Connection getConnection() {
- return con;
- }
- public static void connect() {
- if(!isConnected()) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
- System.out.println("[MySQL] Verbindung aufgebaut!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void disconnect() {
- if(isConnected()) {
- try {
- con.close();
- System.out.println("[MySQL] Verbindung geschlossen!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnected() {
- return (con == null ? false : true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement