0

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.

1
  • 1
    You want to know how to "parse" that XML file and extract the database name? Or you want to know how to get the configured database name at runtime using Hibernate classes? Commented Feb 12, 2014 at 21:36

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.