Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.util.ArrayList;
- public final class JDBConnection { //zodanig niemand eraan kan
- private static JDBConnection instance = null;
- private Connection conn = null;
- private JDBConnection(){}
- public void openConnection(String database, String user, String pwd){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- String url = "jdbc:mysql://127.0.0.1/" + database;
- conn = DriverManager.getConnection(url, user, pwd);
- }
- catch (Exception e ){
- System.out.println("Error: " + e);
- }
- }
- public void closeConnection(){
- if(conn != null){
- try{
- conn.close();
- }
- catch (SQLException ex){
- System.out.println("Error: " + ex);
- }
- }
- }
- public static synchronized JDBConnection getJDBConnection() {
- if(instance == null){
- instance = new JDBConnection();
- }
- return instance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement