Your results are correct. The JNDI provided by tomcat is read-only.
You'll need to put your DataSource object into your own JNDI context or
store the DataSource in your ServletContext. Personally I like the idea
of putting the javax.sql.DataSource object in the ServletContext and
using it from there as needed.
--David
Rob Gregory wrote:
Hi Guys and thanks in advance for any pointers.
I am running Tomcat 5.5.9 and would like to remove the need to specify
database configuration details within the context.xml file e.g.
<Resource
name="jdbc/one"
type="javax.sql.DataSource"
username="user"
password="pass"
driverClassName="oracle.jdbc.driver.OracleDriver"
maxIdle="2"
maxWait="5000"
maxActive="50"
validationQuery="SELECT count(*) FROM dual"
url="jdbc:oracle:thin:@server:1521:sid"
/>
I need to provide (apache commons db) datasources 'on the fly' and after
trying every thing I can think of such as trying to register the details
against JNDI as follows:-
//Hashtable env = new Hashtable();
//env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.naming.java.javaURLContextFactory");
//env.put(Context.URL_PKG_PREFIXES, "org.apache.naming");
//System.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext
.RefFSContextFactory");
//System.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.naming.java
.javaURLContextFactory");
//System.setProperty(Context.PROVIDER_URL, " <file:///\\tmp>
file:///tmp");
//InitialContext ic = null;
Context ic = null;
try {
//ic = new InitialContext(env);
ic = new InitialContext();
if (log.isDebugEnabled()) log.debug("Creating logindb
references");
// Construct DriverAdapterCPDS reference
Reference cpdsRef = new
Reference("org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS",
"org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS",
null);
cpdsRef.add(new StringRefAddr("driver", strDriver));
cpdsRef.add(new StringRefAddr("url", strUrl));
cpdsRef.add(new StringRefAddr("user",
objLoginDB.getUsername()));
cpdsRef.add(new StringRefAddr("password",
objLoginDB.getPassword()));
//ic.rebind("java:comp/env/jdbc/cpdslogindb", cpdsRef);
ic.bind("java:/comp/env/jdbc/cpdslogindb", cpdsRef);
if (log.isDebugEnabled()) log.debug("Creating connection
pool");
// Construct PerUserPoolDataSource reference
Reference ref = new
Reference("org.apache.commons.dbcp.datasources.PerUserPoolDataSource",
"org.apache.commons.dbcp.datasources.PerUserPoolDataSourceFactory", null);
ref.add(new StringRefAddr("dataSourceName",
"java:/comp/env/jdbc/cpdslogindb"));
ref.add(new StringRefAddr("defaultMaxActive",
Config.getParam("pool.max.active")));
ref.add(new StringRefAddr("defaultMaxIdle",
Config.getParam("pool.max.idle")));
ref.add(new StringRefAddr("defaultMaxWait",
Config.getParam("pool.max.wait")));
//ic.rebind("jdbc/" + "logindb", ref);
//ic.bind("logindb", ref);
ic.bind("java:/comp/env/jdbc/logindb", ref);
} catch (NamingException ne) {
log.error("Failed while doing JNDI on connection logindb");
log.debug(ne.getMessage(), ne);
}
The results of this indicate that the Tomcat Initial Context seems to be
'READ-ONLY' ??
Any pointers into what I am doing wrong are greatly appreciated.
Thanks
Rob
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]