6 Replies Latest reply on Jan 30, 2003 2:18 PM by dg

    jdbc/ or java:/ or java:/jdbc/ or nothing before datasource?

    dg Newbie

      Does anyone know what the logic is behind using jdbc/ or java:/ or java:/jdbc/ or nothing prepended to a datasource name? which tags should be prepended and which not? I've seen every different form of this and cannot find a solid explanation.
      thanks thanks thanks
      dan

        • 1. Re: jdbc/ or java:/ or java:/jdbc/ or nothing before datasou
          t g Newbie

          E.G. with Sybase
          1. you drop sybase-service.xml in the deploy directory.
          2. locate the jndi name in the file
          SybaseDS
          3. In a session facade bean write:
          InitialContext ctx = new InitialContext();
          DataSource ds = (DataSource) ctx.lookup(java:/SybaseDS);

          • 2. Re: jdbc/ or java:/ or java:/jdbc/ or nothing before datasou
            Juha Lindfors Master

            If you don't want to hard code your data source name into your bean code, you should consider using the private naming space (java:comp/env) rather than looking up the data source directly from your code.

            So assuming you're doing a lookup from an EJB implementation, in your ejb-jar.xml declare the lookup context and name you use in the bean's private name space. Such as:

            <resource-ref>
            <res-ref-name>jdbc/MyBeanDataSource</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
            </resource-ref>

            Then you need to map this private lookup to the JBoss data source name. So in your jboss.xml define for example:

            <resource-ref>
            <res-ref-name>jdbc/MyBeanDataSource</res-ref-name>
            <resource-name>java:/ORA002</resource-name>
            </resource-ref>

            This way, if your datasource changes, you won't have to recompile your bean code to reflect the changes. Only change the deployment descriptors. Also allows you to deploy the same bean to use different data sources.

            In your bean code you lookup the data source by going to the bean private ENC:

            Context ctx = new InitialContex();
            DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/MyBeanDataSource");

            HTH

            • 3. Re: jdbc/ or java:/ or java:/jdbc/ or nothing before datasou
              t g Newbie

              I think if you avoid the jndi lookup and just use java/* it is faster. That is at least a second faster, which matters id data queries.

              • 4. Re: jdbc/ or java:/ or java:/jdbc/ or nothing before datasou
                Gary Kephart Newbie

                What's the next step? How do you map from "java:/ORA002" to the database itself?
                Unlike the original poster, I'm using a JDBC database, and am wondering if I would use "jdbc:odbc:dsn" here instead of "java:/ORA002". If so, would I then edit the msaccess-service.xml file?

                • 5. Re: jdbc/ or java:/ or java:/jdbc/ or nothing before datasou
                  t g Newbie

                  You edit the msaccess-service.xml file, just like you would the sybase-service.xml file. That's the file that has data like username, password, driver name. And by the way you obviously need the jar for your driver in the lib directory.

                  • 6. Re: jdbc/ or java:/ or java:/jdbc/ or nothing before datasou
                    dg Newbie

                    I finally got a connection using this to datasource name PostgresDS - java code:
                    private static final String dataSourceName = "java:/PostgresDS";

                    in ejb-jar.xml between each tag:
                    <resource-ref>
                    <res-ref-name>jdbc/PostgresDS</res-ref-name>
                    <res-type>javax.sql.DataSource</res-type>
                    <res-auth>Container</res-auth>
                    </resource-ref>

                    create jboss.xml in same META-INF directories as ejb-jar.xml:

                    <ejb-name>BookingManager</ejb-name>
                    <jndi-name>ejb/BookingManagerHome</jndi-name>
                    <resource-ref>
                    <res-ref-name>jdbc/PostgresDS</res-ref-name>
                    <jndi-name>java:/PostgresDS</jndi-name>
                    </resource-ref>


                    it only took several hundred hours...
                    d