This is what resource-ref elements in the ejb-jar.xml descriptor are for.
They enable the following code that is portable across all servers:
Context ctx = new InitialContext();
DataSource pool = (DataSource)ctx.lookup("java:comp/env/jdbc/OracleDS");
return pool.getConnection();
given and resource-ref of:
<ejb-jar>
<enterprise-beans>
<session>
...
<!-- JDBC DataSources (java:comp/env/jdbc) -->
<resource-ref>
<description>The OracleDS</description>
<res-ref-name>jdbc/OracleDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
You then need the application server specific mapping from the java:comp/jdbc/OracleDS
application context entry to the actual deployed jndi name of the resource.
xxxxxxxxxxxxxxxxxxxxxxxx
Scott Stark
Chief Technology Officer
JBoss Group, LLC
xxxxxxxxxxxxxxxxxxxxxxxx
----- Original Message -----
From: "Jon Haugsand" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, November 08, 2002 9:03 AM
Subject: [JBoss-user] What is the proper way to name a datasource?
> We have an application that we are trying out on several application
> servers, i.e. Borland, Weblogic and of course JBoss. This
> application uses CMP, but we also need to do some JDBC calls directly,
> and consequently we need to get the name of the datasource from the
> application server.
>
> We do it like this in JBoss:
>
> Context ctx = new InitialContext();
> DataSource pool = (DataSource)ctx.lookup("java:OracleDS");
> return pool.getConnection();
>
> However using "java:" does not work in Borland and Weblogic, it works
> well with:
>
> Context ctx = new InitialContext();
> DataSource pool = (DataSource)ctx.lookup("OracleDS");
> return pool.getConnection();
>
> So, is there a way that works in all cases?
>
> --
> Jon Haugsand, <[EMAIL PROTECTED]>
> Norges Bank, <http://www.norges-bank.no>
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by: See the NEW Palm
> Tungsten T handheld. Power & Color in a compact size!
> http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-user
>
-------------------------------------------------------
This sf.net email is sponsored by: See the NEW Palm
Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user