You simply look up your DataSource via JNDI and call getConnection() on it, for 
example:

  InitialContext  ic = new InitialContext();
  |   DataSource dataSource =
  |       (DataSource) ic.lookup("java:comp/env/jdbc/myDataSource");
  |   Connection conn = dataSource.getConnection
  |   // use the connection for JDBC like normal, make sure to close it 
afterwards

Note that the EJB doing the JNDI lookup needs to have the DataSource declared 
in its name space as follows (in ejb-jar.xml):

  <session>
  |     <ejb-name>MyEJB</ejb-name>
  |     ...
  |     <resource-ref>
  |       <!-- logical name chosen by bean provider -->
  |       <res-ref-name>jdbc/myDataSource</res-ref-name>
  |       <res-type>javax.sql.DataSource</res-type>
  |       <res-auth>Container</res-auth>
  |     </resource-ref>
  |   </session>

... and in jboss.xml:

  <session>
  |     <ejb-name>MyEJB</ejb-name>
  |     ...
  |     <resource-ref>
  |       <!-- same logical name chosen by bean provider -->
  |       <res-ref-name>jdbc/myDataSource</res-ref-name>
  |       <!-- real JNDI name chosen by server admin -->
  |       <jndi-name>java:/theDataSource</jndi-name>
  |     </resource-ref>
  |   </session>

... and in the blah-ds.xml in the deploy folder:

<?xml version="1.0" ?>
  | <datasources>
  |   <local-tx-datasource>
  |     <!-- real JNDI name chosen by server admin -->
  |     <jndi-name>theDataSource</jndi-name>
  |     <connection-url>blah</connection-url>
  |     <driver-class>com.blah.Blah</driver-class>
  |     <user-name>blah</user-name>
  |     <password>halb</password>
  |     <min-pool-size>10</min-pool-size>
  |     <max-pool-size>100</max-pool-size>
  |     <blocking-timeout-millis>5000</blocking-timeout-millis>
  |     <idle-timeout-minutes>15</idle-timeout-minutes>
  |   </local-tx-datasource>
  | </datasources>

Hope this is what you were asking!

Andrew

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3912765#3912765

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3912765


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to