Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String host;
- public static String port;
- public static String database;
- public static String username;
- public static String password;
- public static Connection con;
- public static void connect(){
- if(!isConnected()){
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database+"?autoReconnect=true", username, password);
- System.out.println( Cache.ANSI_GREEN + "[MySQL] Die Verbindung zu MySQL wurde aufgebaut!" + Cache.ANSI_WHITE);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void disconnect(){
- if(isConnected()){
- try {
- con.close();
- System.out.println(Cache.ANSI_RED + "[MySQL] Die Verbindung wurde geschlossen!" + Cache.ANSI_WHITE);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnected(){
- return (con == null ? false : true);
- }
- public static Connection getConnection(){
- return con;
- }
- public static void update(String qry){
- if(isConnected()){
- try {
- con.createStatement().execute(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static ResultSet getResult(String qry){
- ResultSet rs = null;
- if(isConnected()) {
- try {
- return con.createStatement().executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- } else {
- connect();
- try {
- return con.createStatement().executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return rs;
- }
- public static Connection getCon() {
- return con;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement