1 package com.quikj.application.utilities.sqlc; 2 3 import java.sql.*; 4 5 public class DBConnection 6 { 7 public DBConnection(String driver_class) throws Exception 8 { 9 Class.forName(driver_class).newInstance(); 11 instance = this; 12 } 13 14 public void login(String url, 15 String host, 16 String user, 17 String password, 18 String database) throws SQLException 19 { 20 21 if (host.equals("localhost") == true) 22 { 23 host = "127.0.0.1"; 24 } 25 26 String url_str; 28 url_str = new String (url + "://" + host + "/" + database); 29 connection = DriverManager.getConnection(url_str, user, password); 30 31 this.user = user; 32 this.host = host; 33 } 34 35 public void login(String url, 36 String host, 37 String user, 38 String password) throws SQLException 39 { 40 login(url, host, user, password, "test"); 41 } 42 43 public static DBConnection Instance() 44 { 45 return instance; 46 } 47 48 public void dispose() throws SQLException 49 { 50 connection.close(); 51 connection = null; 52 } 53 54 protected void finalize() throws SQLException 55 { 56 if (connection != null) 57 { 58 connection.close(); 59 } 60 } 61 62 public Connection getConnection() 63 { 64 return connection; 65 } 66 67 public String getUser() 68 { 69 return user; 70 } 71 72 public String getHost() 73 { 74 return host; 75 } 76 77 private static DBConnection instance = null; 78 private Connection connection = null; 79 private String user = ""; 80 private String host = ""; 81 } 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | Popular Tags |