use of org.flywaydb.core.internal.dbsupport.FlywaySqlException in project flyway by flyway.
the class DriverDataSource method getConnectionFromDriver.
/**
* Build properties for the Driver, including the given user and password (if any),
* and obtain a corresponding Connection.
*
* @param username the name of the user
* @param password the password to use
* @return the obtained Connection
* @throws SQLException in case of failure
* @see java.sql.Driver#connect(String, java.util.Properties)
*/
protected Connection getConnectionFromDriver(String username, String password) throws SQLException {
Properties props = new Properties(this.defaultProps);
if (username != null) {
props.setProperty("user", username);
}
if (password != null) {
props.setProperty("password", password);
}
Connection connection;
try {
connection = driver.connect(url, props);
} catch (SQLException e) {
throw new FlywaySqlException("Unable to obtain Jdbc connection from DataSource (" + url + ") for user '" + user + "': " + e.getMessage(), e);
}
for (String initSql : initSqls) {
Statement statement = null;
try {
statement = connection.createStatement();
statement.execute(initSql);
} finally {
JdbcUtils.closeStatement(statement);
}
}
connection.setAutoCommit(autoCommit);
return connection;
}
Aggregations