Datasource mapping

Discussions

EJB programming & troubleshooting: Datasource mapping

  1. Datasource mapping (2 messages)

    I'm using Oracle 10gAS. How can I map a datasource in application.xml or datasource.xml or any other descriptor-file in "application-scope", just like this in web.xml:

     <env-entry>
        <env-entry-name>myDataSource</env-entry-name>
        <env-entry-value>jdbc/myDataSource</env-entry-value>
        <env-entry-type>java.lang.String</env-entry-type>
      </env-entry>
  2. Datasource mapping[ Go to top ]

    What I think you're trying to do can be done using Resource References in WebSphere. Sorry, I don't know about the other platforms.
     Using WebSphere's "Plants by WebSphere" as an example....

    web.xml:
          <resource-ref id="ResourceRef_1">
             <res-ref-name> plantsby/PlantsByWebSphereDataSource</res-ref-name>
             <res-type>javax.sql.DataSource</res-type>
             <res-auth>Container</res-auth>
             <res-sharing-scope>Shareable</res-sharing-scope>
          </resource-ref>

    ejbjar.xml:
                <resource-ref id="ResourceRef_2">
                   <res-ref-name> plantsby/PlantsByWebSphereDataSource</res-ref-name>
                   <res-type>javax.sql.DataSource</res-type>
                   <res-auth>Application</res-auth>
                </resource-ref>

    ibm-ejb-jar-bnd.xmi:
    <resRefBindings xmi:id="ResourceRefBinding_1" jndiName="jdbc/PlantsByWebSphereDataSource">
    <resRefBindings xmi:id="ResourceRefBinding_2" jndiName="jdbc/PlantsByWebSphereDataSource">

    The reference binding can be modified after deployment as well.

    Hope it helps,
    Randall Maier
    Versant Corp.
  3. You need to this in web.xml
      <resource-ref>
        <res-ref-name>jdbc/somename/database</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
      </resource-ref>

    in your application you can do JNDI lookup
    like
           InitialContext ic = new InitialContext();
            dataSource = (DataSource) ic.lookup("java:comp/env/jdbc/somename/database");

    In data source.xml
    have jdbc/database

    during deployment On oracle 10g AS it will ask to perform mapping.
    hope it helps