Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.mysql.fabric.jdbc.FabricMySQLDriver;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class DBWorker {
- private static final String URL = "jdbc:mysql://localhost:3306/database";
- private static final String USERNAME = "root";
- private static final String PASSWORD = "root";
- Connection connection;
- public DBWorker() {
- try {
- java.sql.Driver driver = new FabricMySQLDriver();
- DriverManager.registerDriver(driver);
- connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
- if (connection.isClosed()){
- throw new SQLException();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public Connection getConnection(){
- return connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement