0 Replies Latest reply on Feb 28, 2004 11:31 AM by null null

    Exception accessing DataSource

    null null Newbie

      I am facing an error
      I am trying to configure Microsoft Access as DataSource
      Therefore I copied msaccess-ds.xml to E:\jboss-3.2.3\server\default\deploy with some changes

      I have made a DSN named CSO which points to cso.mdb in my Windows 2000 System

      The Whole code is copied into

      I am new to JBoss

      Sp Please convey my shortcomings or if u need more information please convey it it me

      msaccess-ds.xml

      <?xml version="1.0" encoding="UTF-8"?>
      
      <!-- ===================================================================== -->
      <!-- -->
      <!-- JBoss Server Configuration -->
      <!-- -->
      <!-- ===================================================================== -->
      
      <!-- $Id: msaccess-ds.xml,v 1.1 2002/07/22 22:57:24 d_jencks Exp $ -->
      <!-- ==================================================================== -->
      <!-- This uses the sun jdbc-odbc driver, so don't expect miracles -->
      <!-- Thanks to Alan Moor, who warns... -->
      <!-- Remember, though, never trust critical data, or data that you can't -->
      <!-- afford to lose, or data that you need quick access to, or data that -->
      <!-- needs to be secure, to Microsoft Access. -->
      <!-- ===================================================================== -->
      
      
      <datasources>
       <local-tx-datasource>
       <jndi-name>MSAccessDS</jndi-name>
       <!-- format of URL is "jdbc:odbc:DSNNAME" -->
       <connection-url>jdbc:odbc:CSO</connection-url>
       <driver-class>sun.jdbc.odbc.JdbcOdbcDriver</driver-class>
       <user-name>x</user-name>
       <password>y</password>
       </local-tx-datasource>
      
      </datasources>
      


      GreetingBean.java
      package com.ejb.greeting;
      
      import java.rmi.RemoteException;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;
      import javax.sql.*;
      import java.sql.*;
      import javax.ejb.*;
      import javax.naming.*;
      
      public class GreetingBean implements SessionBean {
      
       private static Context getInitialContext() throws NamingException
       {
      
       java.util.Hashtable JNDIParm = new java.util.Hashtable();
       JNDIParm.put(Context.PROVIDER_URL, "localhost");
       JNDIParm.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       JNDIParm.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
       javax.naming.InitialContext ctx = new InitialContext(JNDIParm);
       //javax.naming.InitialContext ctx = new InitialContext();
       return ctx;
      
       }
      
      
       public String hello(String name) {
      
       String helloName = "Hello " + name;
       DataSource ds=null;
       Connection conn=null;
       try{
       Context ic=getInitialContext();
       ds=(DataSource)ic.lookup("MSAccessDS");
       System.out.println(ds.toString());
       }
       catch(Exception ex)
       {
       ex.printStackTrace();
       return helloName;
       }
       return helloName;
       }
      
      
       public GreetingBean() {}
       public void ejbCreate() {}
       public void ejbRemove() {}
       public void ejbActivate() {}
       public void ejbPassivate() {}
       public void setSessionContext(SessionContext sc) {}
      
      }
      


      ejb-jar.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      <ejb-jar >
       <description>No Description</description>
       <display-name>Greeting EJB</display-name>
       <enterprise-beans>
       <session >
       <ejb-name>Greeting</ejb-name>
       <home>com.ejb.greeting.GreetingHome</home>
       <remote>com.ejb.greeting.Greeting</remote>
       <ejb-class>com.ejb.greeting.GreetingBean</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Bean</transaction-type>
      
       <resource-ref>
       <description>Default Database Connection</description>
       <res-ref-name>jdbc/mdbTEST</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
       </resource-ref>
       <resource-ref>
       <description>Default Database Connection</description>
       <res-ref-name>MSAccessDS</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
       </resource-ref>
      
       </session>
       </enterprise-beans>
      </ejb-jar>
      


      jboss.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
      
      <jboss>
      
       <enterprise-beans>
      
       <entity>
       <ejb-name>Greeting</ejb-name>
       <jndi-name>ejb/greeting/MyGreeting</jndi-name>
      
       <resource-ref>
       <res-ref-name>jdbc/mdbTEST</res-ref-name>
       <jndi-name>java:/mdbTEST</jndi-name>
       </resource-ref>
       </entity>
      
       </enterprise-beans>
      
      
      </jboss>
      



      Greeting1.java
      package GreetingClient;
      import java.io.*;
      //import javax.servlet.*;
      //import javax.servlet.http.*;
      import com.ejb.greeting.Greeting;
      import com.ejb.greeting.GreetingHome;
      import javax.ejb.*;
      import javax.naming.*;
      import javax.rmi.PortableRemoteObject;
      import java.rmi.RemoteException;
      import java.lang.*;
      import java.util.*;
      import javax.sql.*;
      import java.sql.*;
      
      class Greeting1
      {
       private Greeting greeting;
       private DataSource ds=null;
       private Connection conn=null;
      
       public static Context getInitialContext() throws NamingException
       {
      
       java.util.Hashtable JNDIParm = new java.util.Hashtable();
       JNDIParm.put(Context.PROVIDER_URL, "localhost");
       JNDIParm.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       JNDIParm.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
       javax.naming.InitialContext ctx = new InitialContext(JNDIParm);
       //javax.naming.InitialContext ctx = new InitialContext();
       return ctx;
      
       }
      
       public Greeting1()
       {
       try
       {
       InitialContext ic=new InitialContext();
       //InitialContext ic=(InitialContext)getInitialContext();
       System.out.println("Ok till InitialContext");
       Object objRef = ic.lookup("ejb/greeting/MyGreeting");
       //Object objRef = ic.lookup("com/ejb/greeting/Greeting");
       System.out.println("Ok till objref");
       GreetingHome home=(GreetingHome)PortableRemoteObject.narrow(objRef,GreetingHome.class);
       greeting=home.create();
       System.out.println(greeting.hello("Chirag"));
      // ds=(DataSource)ic.lookup("java:jdbc.mdbTest");
       Hellooo();
       }
       catch(RemoteException ex)
       {
       System.out.println("Couldn't create greeting bean." + ex.getMessage());
       }
       catch(CreateException ex)
       {
       System.out.println("Couldn't create greeting bean." + ex.getMessage());
       }
       catch(NamingException ex)
       {
       System.out.println("Unable to look home:" + ex.getMessage() + ex.toString());
       System.out.println(" ");
       ex.printStackTrace();
       }
       System.exit(0);
       };
       public String Hellooo()
       {
       try
       {
       System.out.println(greeting.hello("Hi There"));
       return "Hello";
       }
       catch(RemoteException ex)
       {
       System.out.println("Couldn't create greeting bean." + ex.getMessage());
       return "Error";
       }
       };
       public static void main(String[] args)
       {
       try
       {
       new Greeting1().Hellooo();
       }
       catch(Exception e)
       {
       System.out.println(e.getMessage());
       }
       };
      }
      


      Error at Client Side
      Ok till InitialContext
      Ok till objref
      Hello
      Unable to look home:nulljavax.naming.CommunicationException [Root exception is j
      ava.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
       java.lang.SecurityException: Prohibited package name: java.lang]
      
      javax.naming.CommunicationException. Root exception is java.rmi.UnmarshalExcept
      ion: Error unmarshaling return; nested exception is:
       java.lang.SecurityException: Prohibited package name: java.lang
      java.lang.SecurityException: Prohibited package name: java.lang
       at java.lang.ClassLoader.defineClass(Unknown Source)
       at java.security.SecureClassLoader.defineClass(Unknown Source)
       at java.net.URLClassLoader.defineClass(Unknown Source)
       at java.net.URLClassLoader.access$100(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClassInternal(Unknown Source)
       at java.lang.Class.forName0(Native Method)
       at java.lang.Class.forName(Unknown Source)
       at java.io.ObjectInputStream.resolveClass(Unknown Source)
       at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
       at java.io.ObjectInputStream.inputClassDescriptor(Unknown Source)
       at java.io.ObjectInputStream.readObject(Unknown Source)
       at java.io.ObjectInputStream.readObject(Unknown Source)
       at java.io.ObjectInputStream.inputArray(Unknown Source)
       at java.io.ObjectInputStream.readObject(Unknown Source)
       at java.io.ObjectInputStream.inputClassFields(Unknown Source)
       at java.io.ObjectInputStream.defaultReadObject(Unknown Source)
       at java.io.ObjectInputStream.inputObject(Unknown Source)
       at java.io.ObjectInputStream.readObject(Unknown Source)
       at java.io.ObjectInputStream.readObject(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:528)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:507)
       at javax.naming.InitialContext.lookup(Unknown Source)
       at GreetingClient.Greeting1.<init>(Greeting.java:50)
       at GreetingClient.Greeting1.main(Greeting.java:86)
      
      


      Error at Server Side i.e. in JBOSS Server
      21:22:09,938 ERROR [STDERR] javax.naming.NameNotFoundException: MSAccessDS not b
      ound
      21:22:09,938 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(Naming
      Server.java:495)
      21:22:09,938 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(Naming
      Server.java:503)
      21:22:09,938 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingS
      erver.java:509)
      21:22:09,938 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServ
      er.java:282)
      21:22:09,938 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(
      Native Method)
      21:22:09,938 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(N
      ativeMethodAccessorImpl.java:39)
      21:22:09,948 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
      ke(DelegatingMethodAccessorImpl.java:25)
      21:22:09,948 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
      24)
      21:22:09,948 ERROR [STDERR] at sun.rmi.server.UnicastServerRef.dispatch(Unic
      astServerRef.java:261)
      21:22:09,948 ERROR [STDERR] at sun.rmi.transport.Transport$1.run(Transport.j
      ava:148)
      21:22:09,948 ERROR [STDERR] at java.security.AccessController.doPrivileged(N
      ative Method)
      21:22:09,948 ERROR [STDERR] at sun.rmi.transport.Transport.serviceCall(Trans
      port.java:144)
      21:22:09,948 ERROR [STDERR] at sun.rmi.transport.tcp.TCPTransport.handleMess
      ages(TCPTransport.java:460)
      21:22:09,948 ERROR [STDERR] at sun.rmi.transport.tcp.TCPTransport$Connection
      Handler.run(TCPTransport.java:701)
      21:22:09,948 ERROR [STDERR] at java.lang.Thread.run(Thread.java:536)
      21:22:09,948 ERROR [STDERR] at sun.rmi.transport.StreamRemoteCall.exceptionR
      eceivedFromServer(StreamRemoteCall.java:247)
      21:22:09,948 ERROR [STDERR] at sun.rmi.transport.StreamRemoteCall.executeCal
      l(StreamRemoteCall.java:223)
      21:22:09,948 ERROR [STDERR] at sun.rmi.server.UnicastRef.invoke(UnicastRef.j
      ava:133)
      21:22:09,948 ERROR [STDERR] at org.jnp.server.NamingServer_Stub.lookup(Unkno
      wn Source)
      21:22:09,948 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(Namin
      gContext.java:528)
      21:22:09,948 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(Namin
      gContext.java:507)
      21:22:09,948 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialCon
      text.java:347)
      21:22:09,948 ERROR [STDERR] at com.ejb.greeting.GreetingBean.hello(Unknown S
      ource)
      21:22:09,948 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(
      Native Method)
      21:22:09,948 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(N
      ativeMethodAccessorImpl.java:39)
      21:22:09,958 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
      ke(DelegatingMethodAccessorImpl.java:25)
      21:22:09,958 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
      24)
      21:22:09,958 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer$Conta
      inerInterceptor.invoke(StatelessSessionContainer.java:683)
      21:22:09,958 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedCo
      nnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
      21:22:09,958 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.i
      nvokeNext(AbstractTxInterceptor.java:84)
      21:22:09,958 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptorBM
      T.invokeNext(AbstractTxInterceptorBMT.java:144)
      21:22:09,958 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorBMT.invoke
      (TxInterceptorBMT.java:62)
      21:22:09,958 ERROR [STDERR] at org.jboss.ejb.plugins.StatelessSessionInstanc
      eInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
      21:22:09,958 ERROR [STDERR] at org.jboss.ejb.plugins.SecurityInterceptor.inv
      oke(SecurityInterceptor.java:118)
      21:22:09,958 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.invoke(L
      ogInterceptor.java:191)
      21:22:09,958 ERROR [STDERR] at org.jboss.ejb.plugins.ProxyFactoryFinderInter
      ceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
      21:22:09,958 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer.inter
      nalInvoke(StatelessSessionContainer.java:331)
      21:22:09,958 ERROR [STDERR] at org.jboss.ejb.Container.invoke(Container.java
      :700)
      21:22:09,958 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(
      Native Method)
      21:22:09,958 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(N
      ativeMethodAccessorImpl.java:39)
      21:22:09,958 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
      ke(DelegatingMethodAccessorImpl.java:25)
      21:22:09,958 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
      24)
      21:22:09,958 ERROR [STDERR] at org.jboss.mx.capability.ReflectedMBeanDispatc
      her.invoke(ReflectedMBeanDispatcher.java:284)
      21:22:09,958 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MB
      eanServerImpl.java:546)
      21:22:09,968 ERROR [STDERR] at org.jboss.invocation.jrmp.server.JRMPInvoker.
      invoke(JRMPInvoker.java:367)
      21:22:09,968 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(
      Native Method)
      21:22:09,968 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(N
      ativeMethodAccessorImpl.java:39)
      21:22:09,968 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
      ke(DelegatingMethodAccessorImpl.java:25)
      21:22:09,968 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
      24)
      21:22:09,968 ERROR [STDERR] at sun.rmi.server.UnicastServerRef.dispatch(Unic
      astServerRef.java:261)
      21:22:09,968 ERROR [STDERR] at sun.rmi.transport.Transport$1.run(Transport.j
      ava:148)
      21:22:09,968 ERROR [STDERR] at java.security.AccessController.doPrivileged(N
      ative Method)
      21:22:09,968 ERROR [STDERR] at sun.rmi.transport.Transport.serviceCall(Trans
      port.java:144)
      21:22:09,968 ERROR [STDERR] at sun.rmi.transport.tcp.TCPTransport.handleMess
      ages(TCPTransport.java:460)
      21:22:09,968 ERROR [STDERR] at sun.rmi.transport.tcp.TCPTransport$Connection
      Handler.run(TCPTransport.java:701)
      21:22:09,968 ERROR [STDERR] at java.lang.Thread.run(Thread.java:536)
      


      Thanks in advance