Advertisement
Guest User

Untitled

a guest
Apr 5th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. package me.ase.CommandCheckerBlocker.DBConnect;
  2.  
  3. import java.sql.*;
  4.  
  5. public class DatabaseConnection {
  6.     static private Connection connection;
  7.  
  8.     public static Connection getConnection() throws Exception {
  9.         String host = "HOST";
  10.         String user = "USERNAME";
  11.         String db = "DB";
  12.         String pass = "PASSWORD";
  13.         if (connection == null) {
  14.             Class.forName("com.mysql.jdbc.Driver");
  15.             connection = DriverManager.getConnection("jdbc:mysql://" + host + "/" + db, user, pass);
  16.         }
  17.         return connection;
  18.  
  19.     }
  20.  
  21.     public static void setData(String string) throws Exception {
  22.         DatabaseConnection.getConnection().createStatement().executeUpdate(string);
  23.     }
  24.  
  25.     public static ResultSet getData(String string) throws Exception {
  26.         return DatabaseConnection.getConnection().createStatement().executeQuery(string);
  27.     }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement