Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package database;
- import java.sql.*;
- public class databaseConnection {
- private static Connection singletonInstance = null;
- //Private constructor -> Singleton
- private databaseConnection() {
- createConnection();
- }
- public synchronized Connection getDatabaseConnection() {
- if(singletonInstance == null) {
- databaseConnection.singletonInstance = new databaseConnection();
- return databaseConnection.singletonInstance;
- }
- return null;
- }
- private void createConnection() {
- try {
- String driver = "com.mysql.jdbc.Driver";
- Class.forName(driver).newInstance();
- singletonInstance = DriverManager.getConnection("jdbc:mysql://localhost:3306/111,111,111");
- }
- catch(Exception e) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement