简体   繁体   中英

Apache Wicket application global settings for database connection

I wrote small web application with wicket and sql2o. I have several DAO classes where I create new Sql2o instances with hardcoded username and password:

Sql2o database = new Sql2o("jdbc:oracle:thin:@127.0.0.1:1521:test", "test", "test");

If I change password I would have to change it everywhere. So my question is where and how to put these settings in wicket so it could be accessed from different classes. Maybe I should use .properties file?

You can use a .properties file, where you need to type:

jdbc.url=jdbc:oracle:thin:@//localhost:1521/your_database
jdbc.username=user
jdbc.password=password

The URL should be chaged to one of the following depending on you configurations

  1. jdbc:oracle:thin:@host:port/service
  2. jdbc:oracle:thin:@host:port:SID (SID - System ID of the Oracle server database instance.)
  3. jdbc:oracle:thin:@myhost:1521:databaseInstance (By default, Oracle Database 10g Express Edition creates one database instance called XE.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM