i need access to several databases per environment. Until now i've only seen examples with exactly one database connection config per environment in database.properties. Is it possible to have several connection configs in there for an environment and let ActiveJdbc handle opening the correct one when using DB.open("first") or do i need to load these configs by myself in that case?
Asked
Active
Viewed 163 times
1 Answers
0
You can have named connections and bind them to your thread:
new DB("corporation").open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/test", "root", "p@ssw0rd");
new DB("university").open("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@localhost:1521:xe", "activejdbc", "activejdbc");
After that, you can declare models to associate with named connections:
@DbName("corporation")
public class Employee extends Model {}
...
@DbName("university")
public class Student extends Model {}
For more, see the doc for your case: http://javalite.io/database_connection_management#multiple-database-example

ipolevoy
- 5,432
- 2
- 31
- 46
-
Ok that's what i'm finally using now. I've written my own connection pool manager (which handles the different DataSource instances from the configuration file). – valley Mar 02 '18 at 06:51
-
you might wan to see this then: https://github.com/javalite/activejdbc/blob/master/activejdbc/src/test/java/org/javalite/activejdbc/C3P0PoolTest.java – ipolevoy Mar 03 '18 at 16:08