Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. package FBC;
  2. import java.sql.*;
  3. import java.security.*;
  4. import javax.crypto.*;
  5. import javax.crypto.spec.*;
  6. import java.io.*;
  7. import java.net.*;
  8. import java.util.ArrayList;
  9.  
  10. public class Mysql {
  11.     protected static Connection conn;
  12.     public static ArrayList<String> executeSQL(String sql, String Col) {
  13.         try {
  14.             ArrayList<String> out = new ArrayList<String>();
  15.             ResultSet rs = conn.createStatement().executeQuery(sql);
  16.             while (rs.next() == true){
  17.                     out.add(rs.getString(Col));
  18.                 }
  19.             rs.close();
  20.             return out;
  21.         } catch (SQLException e) {
  22.             System.out.println("==>Mysql<=>SQL ERROR<-->" + e);
  23.         }
  24.         return new ArrayList<String>();
  25.     }
  26.     public static void MysqlConnect() {
  27.         try{
  28.             Class.forName("org.gjt.mm.mysql.Driver");
  29.                 conn = DriverManager.getConnection("jdbc:mysql://localhost/SocialGeek", "SocialGeekGamer", "SocialGeekGamer");
  30.             System.out.println("==>Mysql<=>Connected");
  31.         } catch (Exception err) {
  32.             System.out.println("==>Mysql<=>Conection ERROR<-->" + err);
  33.         }
  34.     }
  35.     public static void MysqlReConnect() {
  36.         try{
  37.                     conn.close();
  38.             System.out.println("==>Mysql<=>Disconnected");
  39.             MysqlConnect();
  40.         } catch (Exception err) {
  41.             System.out.println("==>Mysql<=>Conection ERROR<-->" + err);
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement