1 16 17 package org.apache.commons.dbcp; 18 import java.sql.Connection ; 19 import java.sql.DriverManager ; 20 import java.sql.SQLException ; 21 import java.util.Properties ; 22 23 30 public class DriverManagerConnectionFactory implements ConnectionFactory { 31 32 public DriverManagerConnectionFactory(String connectUri, Properties props) { 33 _connectUri = connectUri; 34 _props = props; 35 } 36 37 public DriverManagerConnectionFactory(String connectUri, String uname, String passwd) { 38 _connectUri = connectUri; 39 _uname = uname; 40 _passwd = passwd; 41 } 42 43 public Connection createConnection() throws SQLException { 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 _connectUri = null; 56 protected String _uname = null; 57 protected String _passwd = null; 58 protected Properties _props = null; 59 } 60 | Popular Tags |