Jboss hangs-- urgent
amar_singhal May 17, 2002 2:22 AM
Hello everybody,
i am using jboss2.4+tomcat.
i have developed a BMP bean. the problem exists when the create() method is called frequently, the server get hangs and dont respond to the request. and after restarting it , it start working . i am using Jdbc Odbc driver.
the code for my bean is
import javax.ejb.*;
import java.rmi.*;
import java.util.*;
import javax.sql.*;
import java.sql.*;
import javax.naming.*;
public class CustomerBean implements EntityBean
{
String id,name,add1,add2,city,state,contact_person,cst_no,lst_no,tele,fax,email,direct,dist;
EntityContext entity_context;
DataSource data_source;
public void setEntityContext(EntityContext entity_context)
{
this.entity_context=entity_context;
try
{
Context c=new InitialContext();
data_source=(DataSource) c.lookup("java:/DefaultDS");
}
catch(NamingException e)
{
throw new EJBException("DataSource name lookup failed"+e);
}
}
public void unsetEntityContext()
{
}
public void ejbRemove()
{
}
public void ejbLoad()
{
try
{
Connection con=data_source.getConnection();
Statement st=con.createStatement();
String sql=" SELECT CUST_CD,CUST_NAME,ADD1,ADD2,CITY,STATE,TELE,FAX,EMAIL,CONT_PER,DIST,CST_NO,LST_NO,DIRECT FROM CUST_MST WHERE CUST_CD='"+id+"'";
ResultSet rs=st.executeQuery(sql);
rs.next();
id=rs.getString("CUST_CD");
name=rs.getString("CUST_NAME");
add1=rs.getString("ADD1");
add2=rs.getString("ADD2");
city=rs.getString("CITY");
state=rs.getString("STATE");
tele=rs.getString("TELE");
fax=rs.getString("FAX");
email=rs.getString("EMAIL");
contact_person=rs.getString("CONT_PER");
dist=rs.getString("DIST");
cst_no=rs.getString("CST_NO");
lst_no=rs.getString("LST_NO");
direct=rs.getString("DIRECT");
rs.close();
st.close();
//con.close();
}
catch(SQLException e)
{
throw new EJBException(e);
}
}
public void ejbStore()
{
try
{
Connection con=data_source.getConnection();
Statement st=con.createStatement();
String sql="UPDATE CUST_MST SET "+
" CUST_CD='"+id+"',"+
" CUST_NAME='"+name+"',"+
" ADD1='"+add1+"',"+
" ADD2 ='"+add2+"',"+
" CITY ='"+city+"',"+
" STATE='"+state+"',"+
" TELE='"+tele+"',"+
" FAX ='"+fax+"',"+
" EMAIL ='"+email+"',"+
" CONT_PER ='"+contact_person+"',"+
" DIST ='"+dist+"',"+
" CST_NO ='"+cst_no+"',"+
" LST_NO ='"+lst_no+"',"+
" DIRECT='"+direct+"' "+
" WHERE CUST_CD='"+id+"'";
st.executeUpdate(sql);
st.close();
//con.close();
}
catch(SQLException e)
{
throw new EJBException(e);
}
}
public void ejbActivate()
{
id=(String)entity_context.getPrimaryKey();
}
public void ejbPassivate()
{
}
public String ejbFindByPrimaryKey(String id)
throws FinderException
{
try
{
Connection con=data_source.getConnection();
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("SELECT * FROM CUST_MST WHERE CUST_CD='"+id+"'");
if(rs.next()) return id;
else throw new ObjectNotFoundException("No Customer with id="+id);
}catch(SQLException e)
{
throw new EJBException(e);
}
}
public Collection ejbFindByNameContaining(String str)
throws FinderException
{
try
{
Connection con=data_source.getConnection();
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("SELECT * FROM CUST_MST WHERE CUST_NAME LIKE '%"+str+"%'");
ArrayList ary=new ArrayList();
while (rs.next())
{
ary.add(rs.getString("CUST_CD"));
}
rs.close();
st.close();
//con.close();
return ary;
}catch(SQLException e)
{
throw new EJBException(e);
}
}
public Collection ejbFindByCity(String str)
throws FinderException
{
try
{
Connection con=data_source.getConnection();
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("SELECT * FROM CUST_MST WHERE CITY='"+str+"'");
ArrayList ary=new ArrayList();
while (rs.next())
{
ary.add(rs.getString("CUST_CD"));
}
rs.close();
st.close();
//con.close();
return ary;
}catch(SQLException e)
{
throw new FinderException(e.toString());
}
}
public Collection ejbFindByState(String str)
throws FinderException
{
try
{
Connection con=data_source.getConnection();
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("SELECT * FROM CUST_MST WHERE STATE='"+str+"'");
ArrayList ary=new ArrayList();
while (rs.next())
{
ary.add(rs.getString("CUST_CD"));
}
rs.close();
st.close();
//con.close();
return ary;
}catch(SQLException e)
{
throw new FinderException(e.toString());
}
}
public void ejbPostCreate(String id, String name,String add1, String add2,String city,
String state,String contactperson,String cst_no, String lst_no,String tele,String fax,
String email,String dist,String direct)
{
}
public String ejbCreate(String id, String name,String add1, String add2,String city,
String state,String contactperson,String cst_no, String lst_no,String tele,String fax,
String email,String dist,String direct) throws CreateException
{
id=id.toUpperCase();
name=name.toUpperCase();
add1=add1.toUpperCase();
add2=add2.toUpperCase();
city=city.toUpperCase();
state=state.toUpperCase();
contactperson=contactperson.toUpperCase();
cst_no=cst_no.toUpperCase();
lst_no=lst_no.toUpperCase();
tele=tele.toUpperCase();
fax=fax.toUpperCase();
dist=dist.toUpperCase();
email=email;
direct=direct.toUpperCase();
try
{
Connection con=data_source.getConnection();
Statement st=con.createStatement();
String sql=" INSERT INTO CUST_MST ("+
" CUST_CD,CUST_NAME,ADD1,ADD2,CITY,STATE,CONT_PER,CST_NO,LST_NO,TELE,FAX,EMAIL,DIST,DIRECT) "+
" VALUES('"+id+"','"+name+"','"+add1+"','"+add2+"','"+city+"','"+state+"','"+contactperson+"','"+cst_no+"','"+lst_no+"','"+tele+"','"+fax+"','"+email+"','"+dist+"','"+direct+"') ";
st.executeUpdate(sql);
st.close();
//con.close();
this.id=id.toUpperCase();
this.name=name.toUpperCase();
this.add1=add1.toUpperCase();
this.add2=add2.toUpperCase();
this.city=city.toUpperCase();
this.state=state.toUpperCase();
this.contact_person=contactperson.toUpperCase();
this.cst_no=cst_no.toUpperCase();
this.lst_no=lst_no.toUpperCase();
this.tele=tele.toUpperCase();
this.fax=fax.toUpperCase();
this.email=email;
this.dist=dist.toUpperCase();
this.direct=direct.toUpperCase();
return id;
}catch(SQLException e)
{
System.out.println(e);
throw new EJBException(e);
}
}
public String getName() throws RemoteException
{
return name;
}
public void setName(String str) throws RemoteException
{
name=str;
}
public String getAdd1() throws RemoteException
{
return add1;
}
public void setAdd1(String str) throws RemoteException
{
add1=str;
}
public String getAdd2() throws RemoteException
{
return add2;
}
public void setAdd2(String str) throws RemoteException
{
add2=str;
}
public String getCity() throws RemoteException
{
return city;
}
public void setCity(String str) throws RemoteException
{
city=str;
}
public String getState() throws RemoteException
{
return state;
}
public void setState(String str) throws RemoteException
{
state=str;
}
public String getTele() throws RemoteException
{
return tele;
}
public void setTele(String str) throws RemoteException
{
tele=str;
}
public String getFax() throws RemoteException
{
return fax;
}
public void setFax(String str) throws RemoteException
{
fax=str;
}
public String getContPer() throws RemoteException
{
return contact_person;
}
public void setContPer(String str) throws RemoteException
{
contact_person=str;
}
public String getDist() throws RemoteException
{
return dist;
}
public void setDist(String str) throws RemoteException
{
}
public String getLstno() throws RemoteException
{
return lst_no;
}
public void setLstno(String str) throws RemoteException
{
lst_no=str;
}
public String getDirect() throws RemoteException
{
return direct;
}
public void setDirect(String str) throws RemoteException
{
direct=str;
}
public String getCstno() throws RemoteException
{
return cst_no;
}
public void setCstno(String str) throws RemoteException
{
cst_no=str;
}
private String isNull(String str,String str1)
{
if (str==null) str=str1;
else str=str.trim().toUpperCase();
return str;
}
private String isNull(String str)
{
return isNull(str,"");
}
}
please repond asap
with regards
Amar