Hey Ric,

Here's another thing you could do:
http://stackoverflow.com/questions/7195556/how-to-manage-connections-to-dynamically-created-databases

If your databases are all on the same db instance, but different
schema/database name, you could avoid connecting to the specific database
name, but rather set that up on the connection object, e.g.

@Resource(name="....")
private DataSource datasource;

public void someMethod() {

  try
    (
      Connection c = datasource.getConnection();
      c.setCatalog("dynamic_dbname");
      PreparedStatement ps = c.prepareStatement("SOME SQL HERE");
    )
  {
    ...
  } catch (SQLException sqle) {
    ...
  }

}

I haven't tried this myself, but I guess this could work. Off course,
working with Spring JdbcTemplate makes it even nicer :))

How long do these dbs live? How often do you create them? Why do you have a
need for that many databases? etc...

Hope that helps!

Cheers!
Neven

Reply via email to