Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.lab1;
- import java.sql.Connection;
- import java.sql.SQLException;
- import org.apache.commons.dbcp2.BasicDataSource;
- public class DatabaseConnector {
- static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
- static final String DB_URL = "jdbc:mysql://localhost:9797/";
- static final String USER = "root";
- static final String PASS = "9797";
- BasicDataSource ds;
- public void connect(String dbName) throws Exception {
- ds = new BasicDataSource();
- ds.setDriverClassName(JDBC_DRIVER);
- ds.setUsername(USER);
- ds.setPassword(PASS);
- ds.setUrl(DB_URL);
- }
- public Connection getConnection () throws SQLException {
- if (ds == null)
- throw new SQLException("Not connected to DB");
- return ds.getConnection();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement