• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC with Session Beans

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi:
I am using a session bean to access the database and I am getting the following error when I run the client
--Application threw an exception :AbstractMethodError:Chronos_stub.getEmail()Ljava/sql/ResultSet:
Also in the command prompt where I have started the J2ee server it gives a message saying that
"java.comp:/env/ChronosCoreUser is using a JNDI name that is not bound :ChronosCoreUser"
can anyone pl throw some light on this error.
___________________________________________________________
Chronos.java
----------------------------------------------------------
public interface Chronos extends EJBObject {

//gets email id of the user whose name is passed in as a parameter

public ResultSet getEmail() throws RemoteException;

}
---------------------------------------------------------
ChronosBean.java
----------------------------------------------------------
public class ChronosBean implements SessionBean {

public DataSource ds=null;
// String datasourcename="java:comp/env/ChronosCoreUser";
String datasourcename="ChronosCoreUser";

ResultSet rs;
public ResultSet getEmail(){
try{
InitialContext ctx=new InitialContext();
ds=(DataSource)ctx.lookup(datasourcename);
Connection conn=ds.getConnection();
Statement stmt=conn.createStatement();
rs=stmt.executeQuery("select email from core_user where firstname='xyz'");

// while(rs.next()){
// System.out.println("The email id is "+rs.getString("email"));
// emailid= rs.getString("email");
//}

}
catch(Exception e){
System.out.println(e);
}

//System.out.println("I am at the Bean implementation ----> "+returnvalue);
return rs;
}
---------------------------------------------------------
ChronosClient.java
----------------------------------------------------------

public static void main(String[] args) {
try {

Context initial = new InitialContext();
Object objref = initial.lookup("ChronosUsrMailid");
ChronosHome home = (ChronosHome)PortableRemoteObject.narrow(objref,ChronosHome.class);
Chronos usermailid = home.create();
ResultSet rs=usermailid.getEmail();
while(rs.next()){
System.out.println("Email of Hemanth is "+ rs.getString("Email"));
}

// System.out.println(usermailid.getEmail());

}
catch (Exception ex) {
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
}
} ChornosClient.java
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you didn't define a ejb resource ref in your deployment descriptors. You might want to double-check.
 
Venkatesh Kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stoddard
Thanks for your reply.
Can you pl let me know how i can define the resource in DD.
How would I mention in the DD,which datbase to access from ???
 
Venkatesh Kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi:
The resource-ref part looks like :
- <resource-ref>
<res-ref-name>ChronosCoreUser</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should consult the DTD for information on what you need to declare. Keep in mind that you could just as easily just bind an actual DataSource in JNDI instead of just the DSN. That would be much easier, since the container will be very capable of managing the DataSource for you.
In addition, if you wanted to forego the whole resource-ref issue, you could just drop the "java:comp/env" portion your name being looked up, and you wouldn't get the error. (Unless of course the rest of the name isn't correctly bound either.)
In the meantime, I would consult the documentation on using resource references in your ejb deployment descriptors.
 
Venkatesh Kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ALL;
I am using J2EE RI server.I am trying to connect to the database but I am getting an NamingException .It says that the JNDI name I am specifying for the database is not bound .
I know where the problem lies,I have to bind the JNDI name to the the object(database)
Can anyone mention , which confiquration files I need to change for the database to be recognised.
I am using SQL Server 2000 database
Database name :Chronos
DSN name : Chronos
In the bean code :...java:comp/env/ChronosCoreUser
Driver used is SQL Server
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure how the RI handles databases. You could always bind it yourself though.
reply
    Bookmark Topic Watch Topic
  • New Topic