Getting DataSource using JNDI in weblogic5.1


EJB programming & troubleshooting: Getting DataSource using JNDI in weblogic5.1

  1. Hi ,

    in i have defined connection pool and JNDI name for that connection like ...

    weblogic.jdbc.connectionPool.oraclePool=\ url=jdbc:weblogic:oracle,\ driver=weblogic.jdbc.oci.Driver,\ loginDelaySecs=1,\ initialCapacity=4,\ maxCapacity=10,\ capacityIncrement=2,\ allowShrinking=true,\ shrinkPeriodMins=15,\ refreshMinutes=10,\ testTable=dual,\ props=user=ermnetdev;password=ermnetdev;server=ermg


    one way to get DataSource thru JNDI name oraclePool is
    defining resource ref during deployment like



    DataSource ds=(DataSource)context.lookup("java:comp/env/jdbc/myDB");

    But i am following a direct route like,

    DataSource ds=(DataSource)context.lookup("oraclePool");

    it is also working fine(so far i have tested).

    My question is

    is my way is correct ? how does it differ from the first one ? is there any chance that my way will create any problem in future ?

    Thanks in advance .

    Regards ,

    Ashim Chakraborty

  2. Hi,

    your first way is more portable than the second and conforms to J2EE standards.

    If you are using the second one and in future want to change the connection to a different pool or change the environment( porting into a new machine) then you are forced to create the pool with the same name and cannot use the existing pool. If you want to use the existing pool you have to change the code.

    If you are using the first just changing the weblogic-ejb-jar.xml will do.

  3. To add more, these XMLs are like JCLs in mainframes which makes the program portable and can change the file etc., outside the code.

    If you dont know about JCL just ignore.

  4. Hi thanks for your reply .
    Rather than hard coding in the code what i have done is ,

    maintaining one cutomdefined class like

    public class Utils
       public static DBJNDINAME = "oraclePool";

    in my bean class i will be using like

    ds = (javax.sql.DataSource)initCtx.lookup(Utils.DBJNDINAME);

    My idea is if any changes is required ( due to change of application server settings ) then i will only change the Utils class .
    I don't have bother about Bean or XML .

    My this idea is working fine in WebLogic 5.1 .

    If any body have some better idea , or find any drawback in my idea please mention it .

    Thanks in advance

    waiting for your ideas and comments.

    Ashim Chakraborty
  5. How do you register your Utils class with JNDI?