Reputation: 587
I just want to know how we can get the database name from the hibernate.cfg.xml
using a java program
Can anyone please help me to get the database name.
Thanks In Advance.
Upvotes: 0
Views: 443
Reputation: 5030
Use hibernate.properties
instead of hibernate.cfg.xml
And in hibernate.properties,,,u can put these properties for database :-
hibernate.database.application=database_name
And u can easily find database name by following code :-
private static Properties props;
props = new Properties();
props.load(PropertiesManager.class.getClassLoader().getResourceAsStream("hibernate.properties"));
String databaseNmae = prop.getProperty("hibernate.database.application");
Upvotes: 1