KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > dbschema > jdbcimpl > ConnectionProvider


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.dbschema.jdbcimpl;
21
22 import java.sql.*;
23 import java.util.ResourceBundle JavaDoc;
24
25 public class ConnectionProvider {
26
27     final ResourceBundle JavaDoc bundle = ResourceBundle.getBundle("org.netbeans.modules.dbschema.resources.Bundle"); // NOI18N
28

29     private Connection con;
30     private DatabaseMetaData dmd;
31
32     private String JavaDoc driver;
33     private String JavaDoc url;
34     private String JavaDoc username;
35     private String JavaDoc password;
36     private String JavaDoc schema;
37
38     /** Creates new ConnectionProvider */
39     public ConnectionProvider(Connection con, String JavaDoc driver) throws SQLException{
40         this.con = con;
41         this.driver = driver;
42         dmd = con.getMetaData();
43     }
44     
45     public ConnectionProvider(String JavaDoc driver, String JavaDoc url, String JavaDoc username, String JavaDoc password) throws ClassNotFoundException JavaDoc, 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 JavaDoc getDriver() {
65         return driver;
66     }
67     
68     public void setSchema(String JavaDoc schema) {
69         this.schema = schema;
70     }
71     
72     public String JavaDoc 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")) // NOI18N
82
System.out.println(bundle.getString("UnableToCloseConnection")); //NOI18N
83
con = null;
84             }
85     }
86 }
87
Popular Tags