aspose file tools*
The moose likes Servlets and the fly likes Servlet becomming slow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet becomming slow" Watch "Servlet becomming slow" New topic
Author

Servlet becomming slow

varkala prabhakar
Ranch Hand

Joined: Sep 08, 2001
Posts: 54
Hi all,
I dont know the mistake what i have made in my servlet, when i start execute my servlet it works fine well with good speed. but as i go on execute this program (say 40 times) then my servlet becomes slow and some times i get the exceptions like code included in the last)
Exception occured
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Cannot open any more tables. at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source) at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source) at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unknown Source) at UpdateCategory.doPost(UpdateCategory.java:91) at javax.servlet.http.HttpServlet.service(HttpServlet.java:521) at javax.servlet.http.HttpServlet.service(HttpServlet.java:588) at sun.servlet.http.HttpServerHandler.sendResponse(HttpServerHandler.java:165) at sun.servlet.http.HttpServerHandler.handleConnection(HttpServerHandler.java:121) at sun.servlet.http.HttpServerHandler.run(HttpServerHandler.java:90) at java.lang.Thread.run(Unknown Source)
CODE:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ShowCategory extends HttpServlet implements Constants{
Connection con;

public void init(ServletConfig config) throws ServletException {
super.init(config);
try{
Class.forName(Constants.DriverString);
con = DriverManager.getConnection(Constants.DataBaseURL);
}
catch(Exception e){
e.printStackTrace();
}
}// End of Init()

public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException {
PrintWriter out = response.getWriter();
response.setContentType("text/html");
String cat = request.getParameter("category");
String randnum=request.getParameter("randnum");
String query;
String rand = null;

Cookie []cook = request.getCookies(); // Use of Cookie

String merid=(String)ht.get(randnum);//added

for(int i = 0; i < cook.length;i++){
if( cook[i].getName().equals(merid) ){
rand = (String)cook[i].getValue() ;
}
}

if( rand == null ) {
out.println("<html><head><title>Error</title></head>");
out.println("<body>");
out.println("<h1>Error! Invalid Login</h1>");
out.println("Your cookie value is invalid");
out.println("Try logging once again");
out.println("</body></html>");
out.close();
return;
}

String merchantid = (String) ht.get(rand);// change the merchantid value

try{
Statement stmt = con.createStatement();
query = "select name from category where categoryid = "+
cat+" ; ";

ResultSet rs = stmt.executeQuery(query);
String cat_name;
if( rs.next() ){
cat_name = rs.getString(1);
out.println("<html><head><title>Viewing Category: "+cat_name+"</title></head>");
}
else{
out.println("<html><head><title>Error!</title></head>");
out.println("<body>");
out.println("<h1>Error!</h1>");
out.println("The given cateogry code "+cat+" does not exist");
out.println("</body></html>");
return;
}// end of If



query = "select categoryid, name from category "
+" where supercategory = "+cat+" ; ";

rs = stmt.executeQuery(query);

out.println("<body>");

out.println("<center><h1>"+cat_name+"</h1></center>");
out.println("<br>");
out.println("<ul>");
int count = 0;


//
out.println("<table width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
out.println("<tr>");
out.println("<td width=\"24%\" BGCOLOR=\"#3399FF\">");
out.println("<font COLOR=\"#FFFF66\">");
while( rs.next() ){
count++;
out.println("<li>");
out.println("<a href="+Constants.HostName+"/servlet/ShowCategory?category="+rs.getString(1)+"&randnum="+randnum+" > "+rs.getString(2)+" </a>");
}// End of While
// 2 lines new code
out.println("<table width=\"98%\" >");
out.println("<tr>");
out.println("</td>");
out.println("<br><br>");
out.println(" <b>Like to move ");
out.println("<a href="+Constants.HostName+"/servlet/ShowCategory?category=0&randnum="+randnum+"> root </a> classification form </b>");
out.println("</td>");
out.println("</tr>");
out.println("</table>");
out.println("</td>");
out.println("</font>");
out.println("<td width=\"76%\">");

//out.println("</ul>");
out.println("<center>");
out.println("<h2>Update Items</h2>");
out.println("<form action="+Constants.HostName+"/servlet/UpdateItem method = POST> ");
out.println("<input type = hidden name = category value = "+cat+" >");
out.println("<input type = hidden name = merchantid value = "+merid+" >");
out.println("<input type = hidden name = randnum value= "+randnum+" >");// added

//System.out.println(" Merchant id in Show Category merchantid:\t"+merchantid+"\n");
//System.out.println(" Merchant id in Show Category merid :\t"+merid+"\n");


out.println("<table colspan=2>");
out.println("<tr>");
out.println("<td align=right>Item Name : ");
out.println("<td><input type=text name = itemname>");// Name of item
out.println("</tr>");
out.println("<tr>");
out.println("<td align=right>Cost : ");
out.println("<td><input type=text name = cost>");// Cost of item
out.println("</tr>");
out.println("<tr>");
out.println("<td align=right>Delivery days : ");
out.println("<td><input type=text name=deliverydays");// No of Delivery Days
out.println("</tr>");
// code added for inserting figure
out.println("<tr>");
out.println("<td align=right>Image GIF Format : ");
out.println("<td><input type=file name=image");// Insert Image
out.println("</tr>");
/*File file1=new File("F:\\mtp\\varkala\\abc.txt");
try{
//file.mkdir();
file1.createNewFile();
}
catch(Exception e){
System.out.println(" Exception Error in Creating File:\t" + e);
}*/



out.println("</table><br>");
out.println("<input type = submit value = submit>");
out.println("</form>");
out.println("</center>");// end of the Update Items display

//

//3 lines new code

out.println("<hr>");
out.println("<br>");out.println("<br>");
out.println("<center>");
out.println("<h2>Add subcategory</h2>");
out.println("<form action="+Constants.HostName+"/servlet/UpdateCategory method = POST >");
out.println("<input type = hidden name = randnum value= "+randnum+" >");// added
out.println("<input type = hidden name = supercategory value = "+cat+" >");
//out.println("<input type=hidden name

out.println("<table>");
out.println("<tr>");
out.println("<td>Category Name : ");
out.println("<td><input type=text name = catname >");
out.println("</tr>");
out.println("</table><br>");
out.println("<input type = submit value = submit>");
out.println("</form>");
out.println("</center>");

out.println("</td>");
out.println("</tr>");
out.println("</table>");
//out.println("<table>");
out.println("</body></html>");
out.close();
}
catch(Exception exp) {
out.println("<html><head><title>Error</title></head>");
out.println("<body>");
out.println("<h1>Error! Exception occured</h1>");
exp.printStackTrace(out);
out.println("</body>");
out.println("</html>");
}


}// End of doGet

}// End of ShowCategory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
thanx for all, helping me.
prabhakar varkala
Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
How crazy
What about using a con.close() at the end of your code? And don't forget using an rs.close()
I haven't looked where to place it, but you your code is missing it.
Good luck!
Erik
matt hooker
Ranch Hand

Joined: Jul 26, 2001
Posts: 46
yup, Eric is right, and for good measure, how about a statement.close() too


Its not what you do, its the way you say you've done it.
varkala prabhakar
Ranch Hand

Joined: Sep 08, 2001
Posts: 54
Hi, thanx for sending me reply, I really missed those simple statements
prabhakar
 
Don't get me started about those stupid light bulbs.
 
subject: Servlet becomming slow