7 Replies Latest reply on Sep 19, 2005 2:21 AM by Veeranjaneyulu Bonthu

    Problem while accessing Oracle datasource from outside of JB

    Veeranjaneyulu Bonthu Newbie

      Hi there

      I am facing difficulty to access the oracle datasource which is deployed in JBOSS server from a stand alone program.Trickiest thing was i have already deployed 2 CMPs on same datasource those are working fine.
      The problem comes when i try to access the datasource from a stand alone program.


      my oracle-ds.xml file is like as below

      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
      <local-tx-datasource>
      <jndi-name>OracleDS</jndi-name>
      <connection-url>jdbc:oracle:thin:@mdc0135c:1521:jxbus</connection-url>
      <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
      <user-name>system</user-name>
      <password>nesschordiant</password>
       <!--<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>-->
      </local-tx-datasource>
      </datasources>


      my standalone program java class is like as below

      public static void main(String[] args)
       {
       Context ctx = null;
       try{
       Hashtable ht = new Hashtable();
       ht.put(Context.INITIAL_CONTEXT_FACTORY ,"org.jnp.interfaces.NamingContextFactory");
       ht.put(Context.PROVIDER_URL,"jnp://localhost:1099");
       ht.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
       ctx = new javax.naming.InitialContext(ht);
       DataSource ds = (DataSource)ctx.lookup("java:/OracleDS");
       Connection con = ds.getConnection();
       PreparedStatement ps = con.prepareStatement("select * from employee");
       ResultSet rs = ps.executeQuery();
       while(rs.next()){
       System.out.println("Employee ID "+rs.getInt("empid")+"Employee Name "+rs.getString("ename")+"Employee Designation "+rs.getString("deptno"));
       }
      
       }catch(Exception e){
       e.printStackTrace();
       }
       }



      The error was like as below

      javax.naming.NameNotFoundException: OracleDS not bound
       at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
       at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
       at sun.rmi.server.UnicastRef.invoke(Unknown Source)
       at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:530)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:509)
       at javax.naming.InitialContext.lookup(Unknown Source)
       at com.ness.training.client.JBOSSDataSourceClient.main(JBOSSDataSourceClient.java:21)



      Pls somebody help by giving some inputs about this problem

      Regards
      Bonthu