• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

properties file and connection pool

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,
Instead of hardcoding the username and password in the class to get connected to the database ( i am using connection pool) i want to put the properties in external file .
so instead of hardcoding scott and tiger as I have in following code I want to use external properties file to get the username and password:
( please note that I am using weblogic connection pool and want to avoid using
DriverManager.getConnetion(). Instead of that I want to use Driver.connect )
String querysql;
ResultSet rs = null;

try {

java.util.Properties props = new java.util.Properties();
props.put("user", "scott");
props.put("password", "tiger");
java.sql.Driver d = (java.sql.Driver)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
java.sql.Connection conn = d.connect("jdbc racle:thin:myhostname", props);

Statement stmt = conn.createStatement();
querysql=" SELECT * FROM EMP"+
"
rs=stmt.executeQuery(querysql);
while(rs.next()) {
..
..
}
if(stmt != null)
stmt.close();
if(conn != null)
conn.close();

}
catch(ClassNotFoundException e) {
}
catch(SQLException e) {
}
catch(Exception e) {
}

Thanks,
smita
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using weblogic connection pool, then you put the username and password in the connection pool configuration. The password will get encrypted in config.xml.
Then you get the connection from the pool.
If you get oracle.jdbc.driver.OracleDriver.connect - that is not a weblogic connection pool.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic