Handle username and password settings.

pull/60/head
Brett Wooldridge 11 years ago
parent e43864f626
commit 14d72a2b29

@ -29,17 +29,25 @@ public final class DriverDataSource implements DataSource
{ {
private final Driver driver; private final Driver driver;
private final String jdbcUrl; private final String jdbcUrl;
private final Properties properties; private final Properties driverProperties;
private PrintWriter logWriter; private PrintWriter logWriter;
private int loginTimeout; private int loginTimeout;
public DriverDataSource(String jdbcUrl, Properties properties) public DriverDataSource(String jdbcUrl, Properties properties, String username, String password)
{ {
try try
{ {
this.jdbcUrl = jdbcUrl; this.jdbcUrl = jdbcUrl;
this.properties = properties; this.driverProperties = new Properties(properties);
if (username != null)
{
driverProperties.put("user", driverProperties.getProperty("user", username));
}
if (password != null)
{
driverProperties.put("password", driverProperties.getProperty("password", password));
}
this.driver = DriverManager.getDriver(jdbcUrl); this.driver = DriverManager.getDriver(jdbcUrl);
} }
catch (SQLException e) catch (SQLException e)
@ -51,13 +59,13 @@ public final class DriverDataSource implements DataSource
@Override @Override
public Connection getConnection() throws SQLException public Connection getConnection() throws SQLException
{ {
return driver.connect(jdbcUrl, properties); return driver.connect(jdbcUrl, driverProperties);
} }
@Override @Override
public Connection getConnection(String username, String password) throws SQLException public Connection getConnection(String username, String password) throws SQLException
{ {
throw new SQLFeatureNotSupportedException("getConnection() with username and password is not supported"); return getConnection();
} }
@Override @Override

Loading…
Cancel
Save