-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Set connection properties dynamically
PostPosted: Wed Jan 31, 2007 1:52 pm 
Beginner
Beginner

Joined: Tue Sep 05, 2006 2:36 pm
Posts: 24
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");
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 31, 2007 2:42 pm 
Beginner
Beginner

Joined: Tue Sep 05, 2006 2:36 pm
Posts: 24
I finally solved this.
The error was that I was usign connection.driver_class instead of hibernate.connection.driver_class.
I also replaced my strings with the constants from the Environment class.

Code:
p.setProperty( Environment.DRIVER, "org.postgresql.Driver" );
p.setProperty( Environment.URL, "jdbc:postgresql://server:5432/db" );
p.setProperty( Environment.USER, "user" );
p.setProperty( Environment.PASS, "pass" );


I don't know if there are differences using setProperty or put.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.