SHARE
TWEET

Untitled

a guest Aug 18th, 2018 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static String url = "jdbc:mysql://localhost:3306/tbabdl?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
  2.     public static String usr = "root";
  3.     public static String mdp = "";
  4.     public static Connection connection = null;
  5.     public static Statement statement = null;
  6.     public static ResultSet resultSet = null;
  7.  
  8.     public static ResultSet Robots(String Mod_W_R, String Query, boolean CloseConnection, boolean Debug) {
  9.  
  10.         /* === MYSQL MOD WRITE === */
  11.         if (Mod_W_R.equalsIgnoreCase("W")) {
  12.             System.out.println("[DatabaseManager:Robots] => Mod:Write");
  13.             System.out.println("[DatabaseManager:Robots] => Mod:Write (INFO) => Query to Execute => " + Query);
  14.             System.out.println("[DatabaseManager:Robots] => Mod:Write (INFO) => Connection");
  15.             try {
  16.                 connection = DriverManager.getConnection(url, usr, mdp);
  17.                 System.out.println("[DatabaseManager:Robots] => Mod:Write (INFO) => Connection SUCCESS");
  18.                 statement = connection.createStatement();
  19.                 int status = statement.executeUpdate(Query);
  20.             } catch (SQLException e) {
  21.                 System.out.println("[DatabaseManager:Robots] => Mod:Write (INFO) => Connection FAIL");
  22.                 e.printStackTrace();
  23.             } finally {
  24.                 if (CloseConnection) { //if true
  25.                     if (connection != null) {
  26.                         System.out.println("[DatabaseManager:Robots] => Mod:Write (INFO) => Closing Connection...");
  27.                         DatabaseCloseConnection();
  28.                     } else {
  29.                         System.out.println("[DatabaseManager:Robots] => Mod:Write (INFO) => Connection return void !");
  30.                     }
  31.                 }
  32.             }
  33.  
  34.         /* === MYSQL MOD READ === */
  35.         } else if (Mod_W_R.equalsIgnoreCase("R")) {
  36.             System.out.println("[DatabaseManager:Robots] => Mod:Read");
  37.             System.out.println("[DatabaseManager:Robots] => Mod:Read (INFO) => Connection");
  38.             try {
  39.                 connection = DriverManager.getConnection(url, usr, mdp);
  40.                 System.out.println("[DatabaseManager:Robots] => Mod:Read (INFO) => Connection SUCCESS");
  41.                 statement = connection.createStatement();
  42.                 resultSet = statement.executeQuery(Query);
  43.             } catch (SQLException e) {
  44.                 System.out.println("[DatabaseManager:Robots] => Mod:Read (INFO) => Connection FAIL");
  45.                 e.printStackTrace();
  46.             } finally {
  47.                 if (CloseConnection) { //if true
  48.                     if (connection != null) {
  49.                         System.out.println("[DatabaseManager:Robots] => Mod:Read (INFO) => Closing Connection...");
  50.                         DatabaseCloseConnection();
  51.                     } else {
  52.                         System.out.println("[DatabaseManager:Robots] => Mod:Read (INFO) => Connection return void !");
  53.                     }
  54.                 }
  55.             }
  56.  
  57.         } else {
  58.             System.out.println("[DatabaseManager:Robots] ERROR Unknown MOD : '" + Mod_W_R + "' PLEASE USE 'W' OR 'R'");
  59.             return null;
  60.         }
  61.         return resultSet;
  62.     }
  63.  
  64.     public static void DatabaseCloseConnection() {
  65.         try {
  66.             connection.close();
  67.         } catch (SQLException e) {
  68.             e.printStackTrace();
  69.         }
  70.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top