Answer the question
In order to leave comments, you need to log in
What is the right way to make it possible to select a database when the application starts?
Good afternoon.
The essence of the question is this.
There is a web application in which the database is registered through persistence.xml, the connection to the database is registered in the application server itself (wildfly), everything is fine, everything works. The problem is that the name of the database can be changed (the database is an archive of events, periodically (I still don’t understand why), a new database is created (with a new name), and the old one simply remains.
How should I proceed in this case? for good , I need to add the ability to choose which database to connect to, but I have absolutely no idea how to do this.
Which way to dig?
PS. I use the javaee stack. Spring is not used.
Answer the question
In order to leave comments, you need to log in
public class EntityManagerFactory {
public static EntityManager get() {
Map<String, Object> properties = new HashMap<>();
properties.put("javax.persistence.jdbc.url", Config.DATABASE_URL);
properties.put("javax.persistence.jdbc.driver", Config.DATABASE_DRIVER);
properties.put("javax.persistence.jdbc.user", Config.DATABASE_USER);
properties.put("javax.persistence.jdbc.password", Config.DATABASE_PWD);
properties.put(PersistenceUnitProperties.WEAVING, "static");
return new PersistenceProvider().createEntityManagerFactory("dbsource_pu", properties).createEntityManager();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question