Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class DbConnection {
- private Connection dbConnection = null;
- public DbConnection() {
- try {
- this.dbConnection = DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/new_db?useSSL=false",
- "root",
- "coderslab"
- );
- } catch(SQLException e) {
- e.printStackTrace();
- }
- }
- public Connection getConnection() {
- return this.dbConnection;
- }
- public void closeConnection() {
- if(this.dbConnection != null) {
- try {
- this.dbConnection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment