Discussions

EJB programming & troubleshooting: DataSource lookup in Client Code in JBOSS 2.2.4

  1. DataSource lookup in Client Code in JBOSS 2.2.4 (3 messages)

    i am using the JBOss 2.2.4 integrated with catalina server.
    I have set the datasource in the jboss_home\conf\catalina\jboss.jcml file as given below.

      <mbean code="org.jboss.jdbc.JdbcProvider" name="DefaultDomain:service=JdbcProvider">
         <attribute name="Drivers">oracle.jdbc.driver.OracleDriver</attribute>
      </mbean>

     
       <mbean code="org.jboss.jdbc.XADataSourceLoader" name="DefaultDomain:service=XADataSource,name=OracleDBPool">
        <attribute name="PoolName">OracleDBPool</attribute>
        <attribute name="DataSourceClass">org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl</attribute>
        <attribute name="Properties"></attribute>
        <attribute name="URL">jdbc:oracle:thin:@oraserver:1521:coutts</attribute>
        <attribute name="GCMinIdleTime">1200000</attribute>
        <attribute name="JDBCUser">eplus</attribute>
        <attribute name="MaxSize">10</attribute>
        <attribute name="Password">eplus</attribute>
        <attribute name="GCEnabled">false</attribute>
        <attribute name="InvalidateOnError">false</attribute>
        <attribute name="TimestampUsed">false</attribute>
        <attribute name="Blocking">true</attribute>
        <attribute name="GCInterval">120000</attribute>
        <attribute name="IdleTimeout">1800000</attribute>
        <attribute name="IdleTimeoutEnabled">false</attribute>
        <attribute name="LoggingEnabled">false</attribute>
        <attribute name="MaxIdleTimeoutPercent">1.0</attribute>
        <attribute name="MinSize">0</attribute>
      </mbean>


    I want to lookup the above datasource in my java client code
    as given below:

    public static void main(String[] args)
    {
    try
             {

    //Sybase jconnect driver
    Properties env=new Properties();

    env.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
    env.setProperty("java.naming.provider.url","jnp://localhost:1099");
                env.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");


    InitialContext namingContext = new InitialContext(env);

                        
    Object obj=namingContext.lookup("java:/OracleDS");
    // DataSource ds = (DataSource)obj;
              System.out.println("--Driver load driver--"+obj);
    }catch(Exception e){
    System.out.println("No DataSource to look up-->"+e.getMessage());
    e.printStackTrace();
    }//end of catch
    System.out.println("---Hello World!---");

    }//end of main

    But it gives me name not bound and unable to lookup.

    Can anybody help me on this problem.

    Thanks in advance,

    REGARDS,
    Jignesh Shah
  2. Hi,
       I dont think that is possible. The (DB)connections can be used only by the beans, but not by the clients. This is as per my knowledge. If it is possible in any server pl. le t me know.
    thanks
    Anil.
  3. actually, I did it once with tomcat32x and jboss using minerva. So I know that it's possible, but for the life of me I can't find the code I wrote.

    Sorry that's not more helpful.
  4. The main problem about applied code for accessing JNDI tree from client code i that client what to access to java:/ subtree which in my opinion can only be accessed from some JVM machine e.g. client code and jboss must be at the same jvm