Guest User

Untitled

a guest
May 27th, 2017
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. public class Database {
  8.     private static Connection c;
  9.     private static ResultSet r;
  10.    
  11.     public static boolean connect(){
  12.         try{
  13.             Class.forName("com.mysql.jdbc.Driver");
  14.             Database.c = DriverManager.getConnection("jdbc:mysql://localhost/Database?user=root&password=1234");
  15.         }catch(ClassNotFoundException | SQLException e){
  16.             e.printStackTrace();
  17.             return false;
  18.         }
  19.         return true;
  20.     }
  21.    
  22.     public static boolean exec(String sql){
  23.         Statement q;
  24.         try{
  25.             q = Database.c.createStatement();
  26.             q.execute(sql);
  27.            
  28.             Database.r = q.getResultSet();
  29.         }catch(SQLException e){
  30.             e.printStackTrace();
  31.             return false;
  32.            
  33.         }
  34.         return true;
  35.     }
  36.    
  37.     public static ResultSet getResults(){
  38.         return Database.r;
  39.     }
  40.    
  41.     public static boolean dc(){
  42.         try{
  43.             Database.c.close();
  44.         }catch(SQLException e){
  45.             e.printStackTrace();
  46.             return false;
  47.         }
  48.         return true;
  49.     }
  50. }
Add Comment
Please, Sign In to add comment