jsf 2 - How can i store database information in JSF2 -


in managed bean need access mysql database. far used code this:

    class.forname("com.mysql.jdbc.driver");      string url = "jdbc:mysql://localhost:3306/test";     string username = "user";     string password = "1234";     connection connection = null;     try {         connection = drivermanager.getconnection(url, username, password); 

now have in more 1 bean, if need change database credentials, have fiddle around in 10 files.

is there

  1. a way store databaseconnection
  2. a way define variables whole web project

thanks in advance

it idea store these kind of values in .properties file. can accessed via java.util.properties (http://docs.oracle.com/javase/7/docs/api/java/util/properties.html)

here tutorial describing how access these files , values, suggest start this: http://www.mkyong.com/java/java-properties-file-examples/

(more information: http://en.wikipedia.org/wiki/.properties)

in ide, create new source package /src/main/config , put configuration-concerning .properties , .xml files in there. if way, need access within jsf application:

string configfilepath = "configuration.properties";  props = new properties();  inputstream propinstream = thread.currentthread().getcontextclassloader().getresourceasstream(configfilepath);  props.load(propinstream); 

or can this: how properties file /web-inf folder in jsf?


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -