-->
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: Connecting without the hibernate.cfg.xml file
PostPosted: Sat Nov 24, 2007 9:05 pm 
Newbie

Joined: Sat Nov 24, 2007 8:51 pm
Posts: 2
hi, I'm new in this forum, and I need some help because I'm building a simple program using hibernate. Well, I connected to mysql using hibernate using the "hibernate.cfg.xml" file and it was all good, but my problem is that I don't know how to connect to mysql, BUT using custom properties, I mean, from my program I want to write "user, password, port, database name" etc. How can I do this if those data are written in the hibernte.cfg.xml in hard code.? How can I change them?.

Thank I hope you can help me...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 25, 2007 7:03 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
You can set properties on the Configuration object before creating the session factory.
Code:
Configuration configuration = new Configuration().configure("/hibernate.cfg.xml");
configuration.setProperty("hibernate.connection.url", "jdbc:mysql://localhost/test")
.setProperty("hibernate.connection.username", "myusername")
.setProperty("hibernate.connection.password", "mypassword");
...create session factory


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.