I have setted the connection properties in
hibernate.cfg.xml file. But now I need to set it in runtime.
I have tried with the Configuration class adding a Property object with the same paremeters I used in the file.
But Hibernate won't connect.
Is there another way to do this?
EDIT: The
cfgURL variable contains an URL to the
hibernate.cfg.xml
Code:
Configuration cfg = new Configuration();
Properties p = new Properties();
p.put("connection.driver_class", "org.postgresql.Driver");
p.put("connection.url", "jdbc:postgresql://server:5432/db");
p.put("connection.username", "user");
p.put("connection.password", "pass");
cfg.addProperties(p);
try{
cfg.configure(cfgURL);
}catch(HibernateException he){
System.out.println("HibernateException caught");
}