users@glassfish.java.net

Re: JDBC via JNDI from Tomcat to Glassfish and back

From: Amy Roh <Amelia.Roh_at_Sun.COM>
Date: Thu, 19 Apr 2007 10:33:40 -0700

glassfish_at_javadesktop.org wrote:
> I have a WAR that runs peachy under Tomcat 5.
>
> In WEB-INF/context.xml, I have a DBPool configured.

BTW, does Tomcat support /WEB-INF/context.xml as well as
/META-INF/context.xml?

http://tomcat.apache.org/tomcat-5.5-doc/config/context.html only
mentions about /META-INF/context.xml.

Thanks,
Amy

> <Context path="/cmsstr">
> <Resource auth="Container" driverClassName="org.postgresql.Driver" maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/postgres" password="password" type="javax.sql.DataSource" url="jdbc:postgresql://localhost:5432/mydb" username="dbuser"/>
> </Context>
>
> In my WAR, I look up my data source like this:
>
> Context ctx = new InitialContext();
> DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/postgres");
>
> However, when I try to deploy this to Glassfish v1b14, I can not seem to duplicate the "java:/comp/env/jdbc/postgres". Glassfish won't let me use the ':'.
>
> Now, I'm not particularly passionate about what name I use, but I would like to know if there is a way I can configure both Tomcat and Glassfish so that I can run this code unchanged, using any name.
>
> I tried a ctx.lookup("jdbc/postgres"), but Tomcat couldn't find that, while Glassfish could.
>
> To be fair this aspect of JNDI has always been a wee bit cloudy to me regarding naming, default naming, required naming, etc.
>
> But if anyone could point the way to getting a common configuration, I'd appreciate it.
> [Message sent by forum member 'whartung' (whartung)]
>
> http://forums.java.net/jive/thread.jspa?messageID=213077
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>