dimanche 3 mai 2015

Programatically set the username and password of a DataSource

I need a datasource to pass into a Spring NamedParameterJdbcTemplate so I can run a parametised query on it.

public void setDataSource(DataSource dataSource)
{
    this.dataSource = dataSource;
    this.jdbcTemplateObject = new NamedParameterJdbcTemplate(dataSource);
}

Set<Integer> parameters = getSomeIds();
List<TableRow> rows = this.jdbcTemplateObject.query(config.getSql(), parameters, new TableRowMapper());

Now this is fine if I'm setting the username and password for the DataSource in the Spring Xml.

However, I need to dynamically assign these. How can I configure the username and password?

Aucun commentaire:

Enregistrer un commentaire