Link to home
Start Free TrialLog in
Avatar of adamretter
adamretter

asked on

Urgent - J2EE Enterprise Beans (BMP) with Microsoft Access???

Please please please help, this is driving me crazy!

Im trying to use a Microsoft Access Database from J2EE Bean Managed
Persistence (BMP) Enterprise Java Beans, and its not working :-[

Im doing a Java course but our lecturer has been absent until very recently
and however his lectures seem to cover general java concepts rather than
practical implementation, ive spent the last two weeks tearing my hair out
over deploying EJB's - but that works now :-)

Okay my platform is - Together 6.0.1, Sun JDK 1.3, Sun J2EE 1.3 Reference
Implementation.

I have created a series of Entity and Session beans, basically empty classes
at the moment, I am now trying to call one of my EJB's and have it return a
record from a database. At the moment I am having trouble making my EJB's
talk to my Microsoft Access Database.

What I have done so far -

1.) Setup a System DSN in ODBC called JAuction that points to my access
database.

2.) Using the Deployment Tool that is bundled with J2EE -
        Tools -> Server Configuration -> DataSources -> Standard

        Here I added a new driver class sun.jdbc.odbc.JdbcOdbcDriver

        I also added a new datasource -
        JNDI Name:     jdbc/JAuction
        JDBC URL:     jdbc:odbc:JAuction

3.) I have a 'UserBean' whoose JNDI name i set to 'UserHome' in the
deployment settings I also give it the resource reference -
    Coded Name:        jdbc/JAuction
    Type:                     javax.sql.DataSource
    Authentication:    Container
    Shareable:            [Ticked]
    JNDI Name:        jdbc/JAuction
    Username:           [blank]
    Password:            [blank]

4.) I verify and deploy my beans to the server using the deployment tool
which all works fine.

However if I call the create method of UserBean from my client app, UserBean
tries to connect to the database and I get an Exception thrown and I dont
know why.

My Client (JFrame1) throws this exception data -

    org.omg.CORBA.UNKNOWN:   minor code: 0 completed: Maybe
     at
com.sun.corba.ee.internal.core.UEInfoServiceContext.<init>(UEInfoServiceCont
ext.java:36)
     at java.lang.reflect.Constructor.newInstance(Native Method)
     at
com.sun.corba.ee.internal.core.ServiceContextData.makeServiceContext(Service
ContextData.java:115)
     at
com.sun.corba.ee.internal.core.ServiceContexts.<init>(ServiceContexts.java:1
10)
     at
com.sun.corba.ee.internal.iiop.messages.ReplyMessage_1_2.read(ReplyMessage_1
_2.java:120)
     at
com.sun.corba.ee.internal.iiop.IIOPInputStream.unmarshalHeader(IIOPInputStre
am.java:126)
     at
com.sun.corba.ee.internal.iiop.IIOPConnection.getResponse(IIOPConnection.jav
a:671)
     at
com.sun.corba.ee.internal.iiop.IIOPOutputStream.invoke(IIOPOutputStream.java
:124)
     at
com.sun.corba.ee.internal.iiop.ClientRequestImpl.invoke(ClientRequestImpl.ja
va:79)
     at
com.sun.corba.ee.internal.corba.ClientDelegate.invoke(ClientDelegate.java:23
2)
     at
com.sun.corba.ee.internal.POA.GenericPOAClientSC.invoke(GenericPOAClientSC.j
ava:96)
     at org.omg.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java:454)
     at _UserHome_Stub.create(Unknown Source)
     at JFrame1.<init>(JFrame1.java:40)
     at JFrame1.main(JFrame1.java:69)


The Sun J2EE RI Server shows this in error.log

    java.rmi.RemoteException: nested exception is: javax.ejb.EJBException:
nested exception is:
        javax.naming.NameNotFoundException;nested exception is:
     javax.ejb.EJBException: nested exception is:
javax.naming.NameNotFoundException
    javax.ejb.EJBException: nested exception is:
javax.naming.NameNotFoundException
    javax.naming.NameNotFoundException
     <<no stack trace available>>
    javax.ejb.EJBException: nested exception is:
javax.naming.NameNotFoundException
     at UserBean.setEntityContext(UserBean.java:51)
     at
com.sun.ejb.containers.EntityContainer.getPooledEJB(EntityContainer.java:123
9)
     at
com.sun.ejb.containers.EntityContainer.getContext(EntityContainer.java:197)
     at
com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:365)
     at UserBean_RemoteHomeImpl.create(UserBean_RemoteHomeImpl.java:22)
     at _UserBean_RemoteHomeImpl_Tie._invoke(Unknown Source)
     at
com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPO
AServerSC.java:520)
     at
com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOA
ServerSC.java:210)
     at
com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC
.java:112)
     at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)
    at
com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.jav
a:84)
    at
com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.jav
a:99)


The code that tries to connect to my ODBC source of my EJB 'UserBean' Entity
Bean is as follows -

public void setEntityContext(javax.ejb.EntityContext context) throws
javax.ejb.EJBException
{
        ctx = context;

        try
        {
            InitialContext initCtx = new InitialContext();

            DataSource dataSource =
(DataSource)initCtx.lookup("java.comp/env/jdbc/JAuction");

            connection = dataSource.getConnection();

        }
        catch(NamingException namingEx)
        {
            throw new EJBException(namingEx);
        }
        catch(SQLException sqlEx)
        {
            throw new EJBException(sqlEx);
        }
}


Thanks Thanks and Thanks again I really need help with this one

Adam.
Avatar of adamretter
adamretter

ASKER

Changed

   initCtx.lookup("java.comp/env/jdbc/JAuction");

TO

   initCtx.lookup("java:comp/env/jdbc/JAuction");



But not the last problem unfortunately...

I now get a RemoteException on the client side, and in the J2EE RI error.log
I get - (again any ideas appreciated)

Warning: Username/password not specified for resource reference
jdbc/JAuction
javax.ejb.EJBException: nested exception is: java.lang.NullPointerException
java.lang.NullPointerException
 at UserBean.ejbCreate(UserBean.java:200)
 at UserBean_RemoteHomeImpl.create(UserBean_RemoteHomeImpl.java:24)
 at _UserBean_RemoteHomeImpl_Tie._invoke(Unknown Source)
 at
com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPO
AServerSC.java:520)
 at
com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOA
ServerSC.java:210)
 at
com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC
.java:112)
 at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)
 at
com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.jav
a:84)
 at
com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.jav
a:99)
javax.ejb.EJBException: nested exception is: java.lang.NullPointerException
 at
com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.ja
va:1558)
 at
com.sun.ejb.containers.BaseContainer.checkExceptionNoTx(BaseContainer.java:1
407)
 at
com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:1267)
 at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:403)
 at UserBean_RemoteHomeImpl.create(UserBean_RemoteHomeImpl.java:30)
 at _UserBean_RemoteHomeImpl_Tie._invoke(Unknown Source)
 at
com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPO
AServerSC.java:520)
 at
com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOA
ServerSC.java:210)
 at
com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC
.java:112)
 at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)
 at
com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.jav
a:84)
 at
com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.jav
a:99)

java.rmi.RemoteException: nested exception is:
java.lang.NullPointerException; nested exception is:
 java.lang.NullPointerException
java.lang.NullPointerException
 at UserBean.ejbCreate(UserBean.java:200)
 at UserBean_RemoteHomeImpl.create(UserBean_RemoteHomeImpl.java:24)
 at _UserBean_RemoteHomeImpl_Tie._invoke(Unknown Source)
 at
com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPO
AServerSC.java:520)
 at
com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOA
ServerSC.java:210)
 at
com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC
.java:112)
 at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)
 at
com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.jav
a:84)
 at
com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.jav
a:99)

ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try to put some username/password for JDBC first and see what happen
Have added the Username and Password "none" and "none" to the resource Reference for my UserBean when I deploy it on J2EE RI as suggested by testn.

I still get a Remote Exception thrown on the client side but I now get the following in my J2EE RI error.log

javax.ejb.EJBException: nested exception is: java.lang.NullPointerException
java.lang.NullPointerException
     at UserBean.ejbCreate(UserBean.java:200)
     at UserBean_RemoteHomeImpl.create(UserBean_RemoteHomeImpl.java:24)
     at _UserBean_RemoteHomeImpl_Tie._invoke(Unknown Source)
     at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPOAServerSC.java:520)
     at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOAServerSC.java:210)
     at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC.java:112)
     at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)
     at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.java:84)
     at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.java:99)
javax.ejb.EJBException: nested exception is: java.lang.NullPointerException
     at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:1558)
     at com.sun.ejb.containers.BaseContainer.checkExceptionNoTx(BaseContainer.java:1407)
     at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:1267)
     at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:403)
     at UserBean_RemoteHomeImpl.create(UserBean_RemoteHomeImpl.java:30)
     at _UserBean_RemoteHomeImpl_Tie._invoke(Unknown Source)
     at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPOAServerSC.java:520)
     at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOAServerSC.java:210)
     at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC.java:112)
     at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)
     at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.java:84)
     at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.java:99)

java.rmi.RemoteException: nested exception is: java.lang.NullPointerException; nested exception is:
     java.lang.NullPointerException
java.lang.NullPointerException
     at UserBean.ejbCreate(UserBean.java:200)
     at UserBean_RemoteHomeImpl.create(UserBean_RemoteHomeImpl.java:24)
     at _UserBean_RemoteHomeImpl_Tie._invoke(Unknown Source)
     at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPOAServerSC.java:520)
     at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOAServerSC.java:210)
     at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC.java:112)
     at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)
     at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.java:84)
     at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.java:99)
Here is ejbCreate from my UserBean as asked for by girionis.



    public Integer ejbCreate() throws CreateException {

          //SQL INSERT

          try{
                 String sqlInsert = "INSERT INTO Users (UserID) VALUES (?)";

                PreparedStatement insertStatement = connection.prepareStatement(sqlInsert);

                insertStatement.setInt(1, UserID.intValue());

                insertStatement.executeUpdate();
                insertStatement.close();

                return(UserID);
        }
          catch(SQLException sqlEx){
                 throw new CreateException(sqlEx.getMessage());
        }

    }


And here is my SetEntityContext method from my UserBean -

public void setEntityContext(javax.ejb.EntityContext context) throws javax.ejb.EJBException {
        ctx = context;

        try
        {
            InitialContext initCtx = new InitialContext();

            DataSource dataSource = (DataSource)initCtx.lookup("java:comp/env/jdbc/JAuction");

            connection = dataSource.getConnection();

        }
        catch(NamingException namingEx)
        {
            throw new EJBException(namingEx);
        }
        catch(SQLException sqlEx)
        {
            throw new EJBException(sqlEx);
        }
    }
 Which one is the line (200) that throws the NllPointerException?
insertStatement.setInt(1, UserID.intValue());
 What is the UserID object here? Where do you initialize it? Can you check if it is null? Just do a System.out.println("UserID: " + UserID); before the  insertStatement.setInt(1, UserID.intValue()); statement.
UserID is just an Integer object.

I think this could be the problem, sorry I am short of time tonight but I will elaborate on this more tomorrow.

Thanks
adamretter:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
This question was never solved and the project was a failure. I wish to remove this question from EE please.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept girionis' comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
 Thank you :)