hi all
I am new to
J2EE as well as Websphere. I am trying to run this AccountBean Example given in the MasteringEJB pdf, in WAS release 4.0.1 Advanced Single Server Edition, OS is Windows 2000 server.The database used is IBM DB2 v7.2.
In the Bean class there is this method "ejbFindByOwnerName(
String Name)" that returns an Enumeration object. When the client calls this method(from the command prompt using "launchclient" command), it throws an exception. The satck trace is as follows:-
Caught exception!
java.util.NoSuchElementException
at com.ibm.ejs.persistence.FinderEnumerator.nextElement(FinderEnumerator.java:122)
at com.ibm.ejs.persistence.FinderEnumeration.nextElement(FinderEnumeration.java:42)
at examples.account.AccountClient.main(AccountClient.java:81)
at java.lang.reflect.Method.invoke(Native Method)
at com.ibm.websphere.client.applicationclient.launchClient.createContainerAndLaunchApp(launchClient.java:430)
at com.ibm.websphere.client.applicationclient.launchClient.main(launchClient.java:288)
at java.lang.reflect.Method.invoke(Native Method)
at com.ibm.ws.bootstrap.WSLauncher.main(WSLauncher.java:158)
Destroying account..
in the command prompt where server is started the log is something like this:-
[00.06.07 11:11:21:033 GMT+05:30] 125e2d81 SystemOut U New Bank Account Entity Bean
Java Object created by EJB Containe
r.
[00.06.07 11:11:21:043 GMT+05:30] 125e2d81 SystemOut U setEntityContext called
[00.06.07 11:11:21:043 GMT+05:30] 125e2d81 SystemOut U ejbFindByOwnerName(John Smith) called
the code for the Finder method is as follows:-
public Enumeration ejbFindByOwnerName(String name) throws FinderException, RemoteException {
PreparedStatement pstmt = null;
Connection conn = null;
Vector v = new Vector();
try {
System.out.println("ejbFindByOwnerName(" + name + ") called");
/*
* Acquire DB connection
*/
conn = getConnection();
/*
* Find the primary keys in the DB
*/
pstmt = conn.prepareStatement("select id from accounts where ownerName = ?");
pstmt.setString(1, name);
ResultSet rs = pstmt.executeQuery();
/*
* Insert every primary key found into a vector
*/
while (rs.next()) {
String id = rs.getString("id");
v.addElement(new AccountPK(id));
}
/*
* Return an enumeration of found primary keys
*/
return v.elements();
}
catch (Exception e) {
throw new FinderException(e.toString());
}
finally {
/*
* Release DB Connection for other beans
*/
try {
pstmt.close();
}
catch (Exception e) { }
try {
conn.close();
}
catch (Exception e) { }
}
}
and the code of the client is as given below:-
Enumeration e = home.findByOwnerName("John Smith");
if (e != null)
{
account = (Account) e.nextElement();
}
else {
throw new Exception("Could not find account");
}
please help!!!
Thanx in advance
Gaurav