Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Database {
- private static Connection c;
- private static ResultSet r;
- public static boolean connect(){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Database.c = DriverManager.getConnection("jdbc:mysql://localhost/Database?user=root&password=1234");
- }catch(ClassNotFoundException | SQLException e){
- e.printStackTrace();
- return false;
- }
- return true;
- }
- public static boolean exec(String sql){
- Statement q;
- try{
- q = Database.c.createStatement();
- q.execute(sql);
- Database.r = q.getResultSet();
- }catch(SQLException e){
- e.printStackTrace();
- return false;
- }
- return true;
- }
- public static ResultSet getResults(){
- return Database.r;
- }
- public static boolean dc(){
- try{
- Database.c.close();
- }catch(SQLException e){
- e.printStackTrace();
- return false;
- }
- return true;
- }
- }
Add Comment
Please, Sign In to add comment