1 4 package org.oddjob.sql; 5 6 import java.sql.Connection ; 7 import java.sql.DriverManager ; 8 import java.sql.SQLException ; 9 10 19 public class ConnectionType { 20 21 26 private String driver; 27 28 33 private String url; 34 35 40 private String username; 41 42 47 private String password; 48 49 57 public Connection valueFor(Class requested) 58 throws SQLException , ClassNotFoundException { 59 Class.forName(driver); 60 if (username == null) { 61 return DriverManager.getConnection(url); 62 } 63 else { 64 return DriverManager.getConnection(url, username, 65 password == null ? "" : password); 66 } 67 } 68 69 74 public String getDriver() { 75 return driver; 76 } 77 78 83 public void setDriver(String driver) { 84 this.driver = driver; 85 } 86 87 92 public String getPassword() { 93 return password; 94 } 95 96 101 public void setPassword(String password) { 102 this.password = password; 103 } 104 105 110 public String getUrl() { 111 return url; 112 } 113 114 119 public void setUrl(String url) { 120 this.url = url; 121 } 122 123 128 public String getUsername() { 129 return username; 130 } 131 132 137 public void setUsername(String username) { 138 this.username = username; 139 } 140 } 141 | Popular Tags |