My context.xml is quite straightforward.
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/postgres"
override="true"
auth="Container"
type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://SERVERNAME:5432/Dionysos"
username="FOO"
password="BAZ"
maxActive="20"
maxIdle="10"
maxWait="1000"
removeAbandoned="true"
removeAbandonedTimeout="15"
logAbandoned="true"
validationQuery="SELECT 1"/>
</Context>
I put it in the META-INF folder of my WAR.
But be advised: If you think you can change the url/username or passwd once the
app has been deployed in Catalina/localhost/WEBAPPNAME.xml it will NOT work.
Regards,
Carsten Pohl
----- Original Message -----
From: "Mike Baranski" <[email protected]>
To: "Tomcat Users List" <[email protected]>, [email protected]
Sent: Tuesday, 3 November, 2009 15:15:45 GMT +01:00 Amsterdam / Berlin / Bern /
Rome / Stockholm / Vienna
Subject: RE: Trouble with context and JNDI resource
OK, thanks, what does your context.xml look like for the jdbc/progress?
>-----Original Message-----
>From: Carsten Pohl [mailto:[email protected]]
>Sent: Tuesday, November 03, 2009 9:03 AM
>To: Tomcat Users List
>Subject: Re: Trouble with context and JNDI resource
>
>Hi,
>
>I am no expert, but your lookup looks strange. (Empty string in lookup).
>Furthermore these two contextes seem "strange" to me.
>
>This works great for me:
> @Override
> public void init() throws ServletException {
> LOGGER.info("INIT has been called");
> try
> {
> final InitialContext initialContext = new InitialContext();
> if ( initialContext == null )
> {
> final String error = "Could not create initialContext.
>Errors WILL happen";
> LOGGER.severe(error);
> throw new ServletException(error);
> }
>
> // actual jndi name is "jdbc/postgres"
> CustomerloungeServlet.datasource = (DataSource)
>initialContext.lookup( "java:/comp/env/jdbc/postgres" );
>
> if ( CustomerloungeServlet.datasource == null )
> {
> final String error = "Could not lookup, Errors WILL happen";
> LOGGER.severe(error);
> throw new ServletException(error);
> }
> }
> catch (NamingException e)
> {
> LOGGER.log(Level.SEVERE,"Namingexception in init",e);
> throw new ServletException(e.getMessage());
> }
> }
>
>
>And I did not put
>
>org.apache.commons.dbcp.BasicDataSource as type of the ressource.
>
>I guess it must be org.apache.commons.dbcp.dbcp..... (I guess) but in
>the tomcat source is string compared to:
>
>"javax.sql.DataSource"
>
>You can try that.
>
>Regards,
>Carsten Pohl
>
>
>
>----- Original Message -----
>From: "Mike Baranski" <[email protected]>
>To: "Tomcat Users List" <[email protected]>
>Sent: Tuesday, 3 November, 2009 14:49:04 GMT +01:00 Amsterdam / Berlin /
>Bern / Rome / Stockholm / Vienna
>Subject: Trouble with context and JNDI resource
>
>I'm using this page, trying to get a resource in a java class:
>
>http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html
>
>I have this in context.xml:
>
>
><Context>
>
> <!-- Default set of monitored resources -->
> <WatchedResource>WEB-INF/web.xml</WatchedResource>
>
> <!-- Uncomment this to disable session persistence across Tomcat
>restarts -->
> <!--
> <Manager pathname="" />
> -->
> <Resource name="proteus" auth="Container"
>type="org.apache.commons.dbcp.BasicDataSource"
> maxActive="100" maxIdle="30" maxWait="10000"
> username="install" password="install"
>driverClassName="com.informix.jdbc.IfxDriver"
>
>url="jdbc:informix-
>sqli://sigma:1960/proteus:INFORMIXSERVER=sigma;IFX_LOCK_M
>ODE_WAIT=-1;IFX_ISOLATION_LEVEL=1">
> </Resource>
></Context>
>
>I have this in web.xml:
>
><resource-env-ref>
> <description>
> Connection pool for xmlrpc.
> </description>
> <resource-env-ref-name>
> proteus
> </resource-env-ref-name>
> <resource-env-ref-type>
> org.apache.commons.dbcp.BasicDataSource
>
> </resource-env-ref-type>
></resource-env-ref>
>
>I have this code:
>
>l.debug("Created the status xmlrpc class");
>Context initCtx = new InitialContext();
>Context envCtx = (Context) initCtx.lookup("");
>this.setDataSource((BasicDataSource) envCtx.lookup("proteus"));
>
>I get this error:
>
>Name proteus is not bound in this Context
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [email protected]
>For additional commands, e-mail: [email protected]
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [email protected]
>For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]