-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDBConnection.java
More file actions
38 lines (31 loc) · 994 Bytes
/
DBConnection.java
File metadata and controls
38 lines (31 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package db;
import pos.database.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author Ronila
*/
public class DBConnection {
private Connection connection;
public static DBConnection dbConnection;
private DBConnection() throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/DB_NAME","DB_USER","DB_PASSWORD");
}
public static DBConnection getInstance() throws ClassNotFoundException, SQLException {
if (dbConnection==null) {
dbConnection=new DBConnection();
}
return dbConnection;
}
public Connection getConnection(){
return connection;
}
}