-->
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.  [ 1 post ] 
Author Message
 Post subject: Getting Connection Parameters from hibernate config files?
PostPosted: Thu Dec 10, 2009 12:04 pm 
Newbie

Joined: Thu Dec 10, 2009 11:59 am
Posts: 1
I am somewhat new to hibernate. I was wondering how to get the username/password@connectstring parameters from the applicationContext-hibernate.xml into my java code?


From the hibernate.xml file:
---------------------------------------------------------------------------------------
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url" value="jdbc:oracle:thin:@vejxsefw3db1506:1521:igdev"/>
<property name="username" value="IGEMS"/>
<property name="password" value="password"/>
---------------------------------------------------------------------------------------



From my code (I don't want to hard code the username password - I want to get the connection information from the hibernate.xml file) - any ideas?:
---------------------------------------------------------------------------------------
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:igdev"; // How do I get from hibernate.xml file?
String username = "igems"; // How do I get from hibernate.xml file?
String password = "Igems12#$"; // How do I get from hibernate.xml file?

Class.forName(driver); // load Oracle driver
Connection conn = DriverManager.getConnection(url, username, password);

String proc3StoredProcedure = "{ call ALERT_MAIL_ATTACH(?, ?, ?, ?, ?, ?, ?) }";

CallableStatement cs = conn.prepareCall(proc3StoredProcedure);

cs.setString(1, fromAddress);
cs.setString(2, tmpToAddress);
cs.setString(3, tmpCcAddress);
cs.setString(4, tmpBccAddress);
cs.setString(5, subject);
cs.setString(6, message);
cs.setString(7, tmpAttachments);

cs.execute();
conn.commit();
conn.close();
---------------------------------------------------------------------------------------


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

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.