tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Defining JDBC resource and AutoDeploy
Date Mon, 03 Oct 2011 17:00:46 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Arttu,

On 10/1/2011 6:04 PM, Arttu Tanner wrote:
> Ok, figured it out. I needed to use InitialContext.lookupLink()
> instead of InitialContext.lookup() what I was using before.

That should not be necessary. Here is the code I have been using for
years using MySQL Connector/J and Tomcat 5.5, 6.0, and 7.0:

        // dataSourceName looks like java:/comp/env/jdbc/myDataSource
        Context context = new InitialContext();
        DataSource ds = (DataSource)context.lookup(dataSourceName);
        if(null == ds)
            throw new NamingException("Found no DataSource for '"
                                      + dataSourceName + "'");
        return ds.getConnection();

It's best to define everything in META-INF/context.xml. Then you don't
need anything anywhere else.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk6J6j4ACgkQ9CaO5/Lv0PBC+ACdHIk6h7Jj2oHN+i+rbsAOhJvd
goMAni7mcKwcdp66b90/SNGXqndw8N/y
=bNIC
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message