Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package connect;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.ResultSet;
- public class DBConnect {
- private Connection connection;
- private Statement stmt;
- public DBConnect() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- // TODO Auto-generated method stub
- String url = "jdbc:mysql://a2plcpnl0797.prod.iad2.secureserver.net:3306/HelperQueue";
- String username ="HelperQueueRoot";
- String password ="HelperQueueRoot";
- System.out.println("Connecting database...");
- try (Connection connection = (Connection) DriverManager.getConnection(url, username, password)) {
- this.connection = connection;
- } catch (SQLException e) {
- throw new IllegalStateException("Cannot connect the database!", e);
- }
- }
- public Connection getConnection() throws SQLException {
- this.stmt = this.connection.createStatement();
- return this.connection;
- }
- public ResultSet getSet(String statement) throws SQLException {
- ResultSet rs = stmt.executeQuery("select * FROM `"+statement+"`");
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement