• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please help !!!!!!!!!!!

 
Gurpreet Saini
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi reader,
I had developed a BMP entity bean. Though it inserts the data in access but I am getting the following error while I try to find the record in database: The error I encounter is :
java.rmi.RemoteException: Exception in ejbFindByPrimaryKey; nested exception is:
javax.ejb.EJBException
- with nested exception:
[java.sql.SQLException: Connection has already been closed.]
Start server side stack trace:
java.rmi.RemoteException: Exception in ejbFindByPrimaryKey; nested exception is:
javax.ejb.EJBException
- with nested exception:
[java.sql.SQLException: Connection has already been closed.]
java.sql.SQLException: Connection has already been closed.
Now, I copy paste my ejbFindBy PrimaryKey method.
public ShipPK ejbFindByPrimaryKey(ShipPK pk) throws FinderException
{
Connection con = null;
PreparedStatement st = null;
try
{
con = this.getConnection();
st = con.prepareStatement("select ship_id from ship where ship_id = ?");
st.setInt(1, pk.id);
ResultSet result = st.executeQuery();

if (!result.next())
throw new ObjectNotFoundException("Cannot found object");
}
catch(SQLException se)
{System.out.println(se); }
finally
{
try
{
if (con != null)
con.close();
if (st != null)
st.close();
}
catch(SQLException e)
{ throw new EJBException(e); }
}
return pk;
}
Please let me know what exactly can be problem.
thank you,
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post your getConnection() method -- my guess is that the problem is actually occuring there.
Kyle
 
Gurpreet Saini
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here, I post getConnection() method.
private Connection getConnection() throws SQLException
{
try {
Context jndiContext = new InitialContext();
DataSource source = (DataSource) jndiContext.lookup("weblogic.data");

return source.getConnection(); }
catch(NamingException ne)
{ throw new EJBException(ne); }
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!