Advertisement
Guest User

DBNEW

a guest
Oct 20th, 2017
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. package connect;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6. import java.sql.ResultSet;
  7.  
  8.  
  9. public class DBConnect {
  10.     private Connection connection;
  11.     private Statement stmt;
  12.     public DBConnect() {
  13.         try {
  14.             Class.forName("com.mysql.jdbc.Driver");
  15.         } catch (ClassNotFoundException e1) {
  16.             // TODO Auto-generated catch block
  17.             e1.printStackTrace();
  18.         }
  19.  
  20.        
  21.         // TODO Auto-generated method stub
  22.         String url = "jdbc:mysql://a2plcpnl0797.prod.iad2.secureserver.net:3306/HelperQueue";
  23.         String username ="HelperQueueRoot";
  24.         String password ="HelperQueueRoot";
  25.        
  26.         System.out.println("Connecting database...");
  27.  
  28.         try (Connection connection = (Connection) DriverManager.getConnection(url, username, password)) {
  29.             this.connection = connection;
  30.         } catch (SQLException e) {
  31.             throw new IllegalStateException("Cannot connect the database!", e);
  32.         }
  33.  
  34.     }
  35.     public Connection getConnection() throws SQLException {
  36.         this.stmt = this.connection.createStatement();
  37.         return this.connection;
  38.     }
  39.     public ResultSet getSet(String statement) throws SQLException {
  40.        
  41.         ResultSet rs = stmt.executeQuery("select * FROM  `"+statement+"`");
  42.         return rs;
  43.        
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement