1 19 20 package org.netbeans.modules.dbschema.jdbcimpl; 21 22 import java.sql.*; 23 import java.util.ResourceBundle ; 24 25 public class ConnectionProvider { 26 27 final ResourceBundle bundle = ResourceBundle.getBundle("org.netbeans.modules.dbschema.resources.Bundle"); 29 private Connection con; 30 private DatabaseMetaData dmd; 31 32 private String driver; 33 private String url; 34 private String username; 35 private String password; 36 private String schema; 37 38 39 public ConnectionProvider(Connection con, String driver) throws SQLException{ 40 this.con = con; 41 this.driver = driver; 42 dmd = con.getMetaData(); 43 } 44 45 public ConnectionProvider(String driver, String url, String username, String password) throws ClassNotFoundException , SQLException { 46 this.driver = driver; 47 this.url = url; 48 this.username = username; 49 this.password = password; 50 51 Class.forName(driver); 52 con = DriverManager.getConnection(url, username, password); 53 dmd = con.getMetaData(); 54 } 55 56 public Connection getConnection() { 57 return con; 58 } 59 60 public DatabaseMetaData getDatabaseMetaData() throws SQLException { 61 return dmd; 62 } 63 64 public String getDriver() { 65 return driver; 66 } 67 68 public void setSchema(String schema) { 69 this.schema = schema; 70 } 71 72 public String getSchema() { 73 return schema; 74 } 75 76 public void closeConnection() { 77 if (con != null) 78 try { 79 con.close(); 80 } catch (SQLException exc) { 81 if (Boolean.getBoolean("netbeans.debug.exceptions")) System.out.println(bundle.getString("UnableToCloseConnection")); con = null; 84 } 85 } 86 } 87 | Popular Tags |