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.JdbcOdbcDriv er
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.UEInf oServiceCo ntext.<ini t>(UEInfoS erviceCont
ext.java:36)
at java.lang.reflect.Construc tor.newIns tance(Nati ve Method)
at
com.sun.corba.ee.internal. core.Servi ceContextD ata.makeSe rviceConte xt(Service
ContextData.java:115)
at
com.sun.corba.ee.internal. core.Servi ceContexts .<init>(Se rviceConte xts.java:1
10)
at
com.sun.corba.ee.internal. iiop.messa ges.ReplyM essage_1_2 .read(Repl yMessage_1
_2.java:120)
at
com.sun.corba.ee.internal. iiop.IIOPI nputStream .unmarshal Header(IIO PInputStre
am.java:126)
at
com.sun.corba.ee.internal. iiop.IIOPC onnection. getRespons e(IIOPConn ection.jav
a:671)
at
com.sun.corba.ee.internal. iiop.IIOPO utputStrea m.invoke(I IOPOutputS tream.java
:124)
at
com.sun.corba.ee.internal. iiop.Clien tRequestIm pl.invoke( ClientRequ estImpl.ja
va:79)
at
com.sun.corba.ee.internal. corba.Clie ntDelegate .invoke(Cl ientDelega te.java:23
2)
at
com.sun.corba.ee.internal. POA.Generi cPOAClient SC.invoke( GenericPOA ClientSC.j
ava:96)
at org.omg.CORBA.portable.Obj ectImpl._i nvoke(Obje ctImpl.jav a:454)
at _UserHome_Stub.create(Unkn own Source)
at JFrame1.<init>(JFrame1.jav a: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.NameNotFoundE xception;n ested exception is:
javax.ejb.EJBException: nested exception is:
javax.naming.NameNotFoundE xception
javax.ejb.EJBException: nested exception is:
javax.naming.NameNotFoundE xception
javax.naming.NameNotFoundE xception
<<no stack trace available>>
javax.ejb.EJBException: nested exception is:
javax.naming.NameNotFoundE xception
at UserBean.setEntityContext( UserBean.j ava:51)
at
com.sun.ejb.containers.Ent ityContain er.getPool edEJB(Enti tyContaine r.java:123
9)
at
com.sun.ejb.containers.Ent ityContain er.getCont ext(Entity Container. java:197)
at
com.sun.ejb.containers.Bas eContainer .preInvoke (BaseConta iner.java: 365)
at UserBean_RemoteHomeImpl.cr eate(UserB ean_Remote HomeImpl.j ava:22)
at _UserBean_RemoteHomeImpl_T ie._invoke (Unknown Source)
at
com.sun.corba.ee.internal. POA.Generi cPOAServer SC.dispatc hToServant (GenericPO
AServerSC.java:520)
at
com.sun.corba.ee.internal. POA.Generi cPOAServer SC.interna lDispatch( GenericPOA
ServerSC.java:210)
at
com.sun.corba.ee.internal. POA.Generi cPOAServer SC.dispatc h(GenericP OAServerSC
.java:112)
at com.sun.corba.ee.internal. iiop.ORB.p rocess(ORB .java:255)
at
com.sun.corba.ee.internal. iiop.Reque stProcesso r.process( RequestPro cessor.jav
a:84)
at
com.sun.corba.ee.internal. orbutil.Th readPool$P ooledThrea d.run(Thre adPool.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 .EntityCon text context) throws
javax.ejb.EJBException
{
ctx = context;
try
{
InitialContext initCtx = new InitialContext();
DataSource dataSource =
(DataSource)initCtx.lookup ("java.com p/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.
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.JdbcOdbcDriv
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.
ext.java:36)
at java.lang.reflect.Construc
at
com.sun.corba.ee.internal.
ContextData.java:115)
at
com.sun.corba.ee.internal.
10)
at
com.sun.corba.ee.internal.
_2.java:120)
at
com.sun.corba.ee.internal.
am.java:126)
at
com.sun.corba.ee.internal.
a:671)
at
com.sun.corba.ee.internal.
:124)
at
com.sun.corba.ee.internal.
va:79)
at
com.sun.corba.ee.internal.
2)
at
com.sun.corba.ee.internal.
ava:96)
at org.omg.CORBA.portable.Obj
at _UserHome_Stub.create(Unkn
at JFrame1.<init>(JFrame1.jav
at JFrame1.main(JFrame1.java:
The Sun J2EE RI Server shows this in error.log
java.rmi.RemoteException: nested exception is: javax.ejb.EJBException:
nested exception is:
javax.naming.NameNotFoundE
javax.ejb.EJBException: nested exception is:
javax.naming.NameNotFoundE
javax.ejb.EJBException: nested exception is:
javax.naming.NameNotFoundE
javax.naming.NameNotFoundE
<<no stack trace available>>
javax.ejb.EJBException: nested exception is:
javax.naming.NameNotFoundE
at UserBean.setEntityContext(
at
com.sun.ejb.containers.Ent
9)
at
com.sun.ejb.containers.Ent
at
com.sun.ejb.containers.Bas
at UserBean_RemoteHomeImpl.cr
at _UserBean_RemoteHomeImpl_T
at
com.sun.corba.ee.internal.
AServerSC.java:520)
at
com.sun.corba.ee.internal.
ServerSC.java:210)
at
com.sun.corba.ee.internal.
.java:112)
at com.sun.corba.ee.internal.
at
com.sun.corba.ee.internal.
a:84)
at
com.sun.corba.ee.internal.
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
javax.ejb.EJBException
{
ctx = context;
try
{
InitialContext initCtx = new InitialContext();
DataSource dataSource =
(DataSource)initCtx.lookup
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try to put some username/password for JDBC first and see what happen
ASKER
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.NullPointerExcep tion
java.lang.NullPointerExcep tion
at UserBean.ejbCreate(UserBea n.java:200 )
at UserBean_RemoteHomeImpl.cr eate(UserB ean_Remote HomeImpl.j ava:24)
at _UserBean_RemoteHomeImpl_T ie._invoke (Unknown Source)
at com.sun.corba.ee.internal. POA.Generi cPOAServer SC.dispatc hToServant (GenericPO AServerSC. java:520)
at com.sun.corba.ee.internal. POA.Generi cPOAServer SC.interna lDispatch( GenericPOA ServerSC.j ava:210)
at com.sun.corba.ee.internal. POA.Generi cPOAServer SC.dispatc h(GenericP OAServerSC .java:112)
at com.sun.corba.ee.internal. iiop.ORB.p rocess(ORB .java:255)
at com.sun.corba.ee.internal. iiop.Reque stProcesso r.process( RequestPro cessor.jav a:84)
at com.sun.corba.ee.internal. orbutil.Th readPool$P ooledThrea d.run(Thre adPool.jav a:99)
javax.ejb.EJBException: nested exception is: java.lang.NullPointerExcep tion
at com.sun.ejb.containers.Bas eContainer .processSy stemExcept ion(BaseCo ntainer.ja va:1558)
at com.sun.ejb.containers.Bas eContainer .checkExce ptionNoTx( BaseContai ner.java:1 407)
at com.sun.ejb.containers.Bas eContainer .postInvok eTx(BaseCo ntainer.ja va:1267)
at com.sun.ejb.containers.Bas eContainer .postInvok e(BaseCont ainer.java :403)
at UserBean_RemoteHomeImpl.cr eate(UserB ean_Remote HomeImpl.j ava:30)
at _UserBean_RemoteHomeImpl_T ie._invoke (Unknown Source)
at com.sun.corba.ee.internal. POA.Generi cPOAServer SC.dispatc hToServant (GenericPO AServerSC. java:520)
at com.sun.corba.ee.internal. POA.Generi cPOAServer SC.interna lDispatch( GenericPOA ServerSC.j ava:210)
at com.sun.corba.ee.internal. POA.Generi cPOAServer SC.dispatc h(GenericP OAServerSC .java:112)
at com.sun.corba.ee.internal. iiop.ORB.p rocess(ORB .java:255)
at com.sun.corba.ee.internal. iiop.Reque stProcesso r.process( RequestPro cessor.jav a:84)
at com.sun.corba.ee.internal. orbutil.Th readPool$P ooledThrea d.run(Thre adPool.jav a:99)
java.rmi.RemoteException: nested exception is: java.lang.NullPointerExcep tion; nested exception is:
java.lang.NullPointerExcep tion
java.lang.NullPointerExcep tion
at UserBean.ejbCreate(UserBea n.java:200 )
at UserBean_RemoteHomeImpl.cr eate(UserB ean_Remote HomeImpl.j ava:24)
at _UserBean_RemoteHomeImpl_T ie._invoke (Unknown Source)
at com.sun.corba.ee.internal. POA.Generi cPOAServer SC.dispatc hToServant (GenericPO AServerSC. java:520)
at com.sun.corba.ee.internal. POA.Generi cPOAServer SC.interna lDispatch( GenericPOA ServerSC.j ava:210)
at com.sun.corba.ee.internal. POA.Generi cPOAServer SC.dispatc h(GenericP OAServerSC .java:112)
at com.sun.corba.ee.internal. iiop.ORB.p rocess(ORB .java:255)
at com.sun.corba.ee.internal. iiop.Reque stProcesso r.process( RequestPro cessor.jav a:84)
at com.sun.corba.ee.internal. orbutil.Th readPool$P ooledThrea d.run(Thre adPool.jav a:99)
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.NullPointerExcep
java.lang.NullPointerExcep
at UserBean.ejbCreate(UserBea
at UserBean_RemoteHomeImpl.cr
at _UserBean_RemoteHomeImpl_T
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
javax.ejb.EJBException: nested exception is: java.lang.NullPointerExcep
at com.sun.ejb.containers.Bas
at com.sun.ejb.containers.Bas
at com.sun.ejb.containers.Bas
at com.sun.ejb.containers.Bas
at UserBean_RemoteHomeImpl.cr
at _UserBean_RemoteHomeImpl_T
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
java.rmi.RemoteException: nested exception is: java.lang.NullPointerExcep
java.lang.NullPointerExcep
java.lang.NullPointerExcep
at UserBean.ejbCreate(UserBea
at UserBean_RemoteHomeImpl.cr
at _UserBean_RemoteHomeImpl_T
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
at com.sun.corba.ee.internal.
ASKER
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.prepareStatemen t(sqlInser t);
insertStatement.setInt(1, UserID.intValue());
insertStatement.executeUpd ate();
insertStatement.close();
return(UserID);
}
catch(SQLException sqlEx){
throw new CreateException(sqlEx.getM essage());
}
}
And here is my SetEntityContext method from my UserBean -
public void setEntityContext(javax.ejb .EntityCon text context) throws javax.ejb.EJBException {
ctx = context;
try
{
InitialContext initCtx = new InitialContext();
DataSource dataSource = (DataSource)initCtx.lookup ("java:com p/env/jdbc /JAuction" );
connection = dataSource.getConnection() ;
}
catch(NamingException namingEx)
{
throw new EJBException(namingEx);
}
catch(SQLException sqlEx)
{
throw new EJBException(sqlEx);
}
}
public Integer ejbCreate() throws CreateException {
//SQL INSERT
try{
String sqlInsert = "INSERT INTO Users (UserID) VALUES (?)";
PreparedStatement insertStatement = connection.prepareStatemen
insertStatement.setInt(1, UserID.intValue());
insertStatement.executeUpd
insertStatement.close();
return(UserID);
}
catch(SQLException sqlEx){
throw new CreateException(sqlEx.getM
}
}
And here is my SetEntityContext method from my UserBean -
public void setEntityContext(javax.ejb
ctx = context;
try
{
InitialContext initCtx = new InitialContext();
DataSource dataSource = (DataSource)initCtx.lookup
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?
ASKER
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.
ASKER
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
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 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.
ASKER
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
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 :)
ASKER
initCtx.lookup("java.comp/
TO
initCtx.lookup("java:comp/
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.NullPointerExcep
java.lang.NullPointerExcep
at UserBean.ejbCreate(UserBea
at UserBean_RemoteHomeImpl.cr
at _UserBean_RemoteHomeImpl_T
at
com.sun.corba.ee.internal.
AServerSC.java:520)
at
com.sun.corba.ee.internal.
ServerSC.java:210)
at
com.sun.corba.ee.internal.
.java:112)
at com.sun.corba.ee.internal.
at
com.sun.corba.ee.internal.
a:84)
at
com.sun.corba.ee.internal.
a:99)
javax.ejb.EJBException: nested exception is: java.lang.NullPointerExcep
at
com.sun.ejb.containers.Bas
va:1558)
at
com.sun.ejb.containers.Bas
407)
at
com.sun.ejb.containers.Bas
at com.sun.ejb.containers.Bas
at UserBean_RemoteHomeImpl.cr
at _UserBean_RemoteHomeImpl_T
at
com.sun.corba.ee.internal.
AServerSC.java:520)
at
com.sun.corba.ee.internal.
ServerSC.java:210)
at
com.sun.corba.ee.internal.
.java:112)
at com.sun.corba.ee.internal.
at
com.sun.corba.ee.internal.
a:84)
at
com.sun.corba.ee.internal.
a:99)
java.rmi.RemoteException: nested exception is:
java.lang.NullPointerExcep
java.lang.NullPointerExcep
java.lang.NullPointerExcep
at UserBean.ejbCreate(UserBea
at UserBean_RemoteHomeImpl.cr
at _UserBean_RemoteHomeImpl_T
at
com.sun.corba.ee.internal.
AServerSC.java:520)
at
com.sun.corba.ee.internal.
ServerSC.java:210)
at
com.sun.corba.ee.internal.
.java:112)
at com.sun.corba.ee.internal.
at
com.sun.corba.ee.internal.
a:84)
at
com.sun.corba.ee.internal.
a:99)