• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem closing the connection

 
Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,
I've got a problem here. Please help me sort it out coz i've got a deadline, and the deadline is really closing in.
I'm developing a chat application.
I'm using Appache server, with the JServ1.1.2 servlet engine.
and im using the MS-SQL database
I need to call a servlet serveral times in my application. But the applications gets hanged the 2nd time i call the servlet. Ive fond the exact position where the servlet gets hanged.
My servlet code goes as below:
public class getList extends HttpServlet
{
private ResultSet rset;
private Connection conn = null;
private Statement stmt =null;
public void init(ServletConfig cfg)
throws ServletException
{
super.init(cfg);
}
public void service(HttpServletRequest req,HttpServletResponse res)
{
// some code
connectDB();
writeHashtable();
// some code
}
private void connectDB()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriverconn = DriverManager.getConnection ("jdbc dbc:"+preServletValues.InstaDatabase);
}
catch (Exception e)
{
//System.out.println("*****err*******" +e);
}
private void writeHashtable() throws Exception
{
try
{
out.writeObject(ht);
in.close();
stmt.close();

// the servlet gets hanged at this point.conn.close();
out.close();

}
catch(Exception e)
{
}

}
}
Please note that the servlet gets hanged only when this servelt is called for the 2nd time from the application. And it gets ahnged just before the 'conn.close();' statement.
Any idea what the problem is ??
Please help
...kindest regards
....sajee
 
prabhat kumar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just check before closing the connection whether it is null or not ...
try {
if(conn!=null)
{
conn.close();
}
}
catch(Exception e){}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic