KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > dbcp > DriverManagerConnectionFactory


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.dbcp;
18 import java.sql.Connection JavaDoc;
19 import java.sql.DriverManager JavaDoc;
20 import java.sql.SQLException JavaDoc;
21 import java.util.Properties JavaDoc;
22
23 /**
24  * A {@link DriverManager}-based implementation of {@link ConnectionFactory}.
25  *
26  * @author Rodney Waldhoff
27  * @author Ignacio J. Ortega
28  * @version $Revision: 1.8 $ $Date: 2004/02/28 12:18:17 $
29  */

30 public class DriverManagerConnectionFactory implements ConnectionFactory {
31
32     public DriverManagerConnectionFactory(String JavaDoc connectUri, Properties JavaDoc props) {
33         _connectUri = connectUri;
34         _props = props;
35     }
36
37     public DriverManagerConnectionFactory(String JavaDoc connectUri, String JavaDoc uname, String JavaDoc passwd) {
38         _connectUri = connectUri;
39         _uname = uname;
40         _passwd = passwd;
41     }
42
43     public Connection JavaDoc createConnection() throws SQLException JavaDoc {
44         if(null == _props) {
45             if((_uname == null) || (_passwd == null)) {
46                 return DriverManager.getConnection(_connectUri);
47             } else {
48                 return DriverManager.getConnection(_connectUri,_uname,_passwd);
49             }
50         } else {
51             return DriverManager.getConnection(_connectUri,_props);
52         }
53     }
54
55     protected String JavaDoc _connectUri = null;
56     protected String JavaDoc _uname = null;
57     protected String JavaDoc _passwd = null;
58     protected Properties JavaDoc _props = null;
59 }
60
Popular Tags