?
Solved

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

Posted on 2003-03-21
14
Medium Priority
?
462 Views
Last Modified: 2013-11-24
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.
0
Comment
Question by:adamretter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 

Author Comment

by:adamretter
ID: 8184956
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)

0
 
LVL 35

Accepted Solution

by:
girionis earned 2000 total points
ID: 8186068
> at UserBean.ejbCreate(UserBean.java:200)

  Can you post a snippet of code around this line of your UserBean file? I tmight help us identify the problem.
0
 
LVL 18

Expert Comment

by:testn
ID: 8186272
Try to put some username/password for JDBC first and see what happen
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:adamretter
ID: 8186602
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)
0
 

Author Comment

by:adamretter
ID: 8186612
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);
        }
    }
0
 
LVL 35

Expert Comment

by:girionis
ID: 8186775
 Which one is the line (200) that throws the NllPointerException?
0
 

Author Comment

by:adamretter
ID: 8187606
insertStatement.setInt(1, UserID.intValue());
0
 
LVL 35

Expert Comment

by:girionis
ID: 8188365
 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.
0
 

Author Comment

by:adamretter
ID: 8188425
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
0
 

Expert Comment

by:CleanupPing
ID: 9058553
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.
0
 

Author Comment

by:adamretter
ID: 9072841
This question was never solved and the project was a failure. I wish to remove this question from EE please.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9730657
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
0
 
LVL 35

Expert Comment

by:girionis
ID: 9730738
 Thank you :)
0

Featured Post

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question