jsp site crashing - need help understanding catalina.out

We have a JSP site that is crashing a lot and we cannot figure out why. I'd like some help understanding some entries in our catalina.out file so I can try to help solve the problem.

Two etnries in the log file I need explained. I am not a java programmer and am new to JSP so I'd appreciate clear, thorough explanations.

One.
+++
Mar 20, 2007 9:11:08 AM org.apache.tomcat.util.threads.ThreadPool$ControlRunnable run
SEVERE: Caught exception (java.lang.OutOfMemoryError: unable to create new native thread) executing org.apache.jk.common.SocketAcceptor@dab859, terminating thread
emilie007emilie007
[Unloading class sun.reflect.GeneratedConstructorAccessor29]
[Unloading class sun.reflect.GeneratedConstructorAccessor28]
emilie007emilie007
+++

The "emilie007emilie007" bit comes from a login page. These were the last entries in the log before the site crashed. What do these entries tell me?


Two.
We get a lot of the following entries in the log and I don't know why. Can anyone explain what they mean?

+++++
[Unloading class sun.reflect.GeneratedConstructorAccessor26]
[Unloading class sun.reflect.GeneratedConstructorAccessor27]
[Loaded sun.reflect.GeneratedConstructorAccessor28 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedConstructorAccessor29 from __JVM_DefineClass__]
+++++

If there is additional information you need, please let me know. Remember I'm very green here! Thanks so much.
atwoodjAsked:
Who is Participating?
 
Mayank SConnect With a Mentor Associate Director - Product EngineeringCommented:
Instead of session.setAttribute (), see if you can use request.setAttribute () so that the session size does not keep growing with objects which are required only for the current request/ page. Also try using StringBuffer/ StringBuilder initialized with the estimated size to do string concatenations instead of the + operator
0
 
KuldeepchaturvediCommented:
>
java.lang.OutOfMemoryError
that one means either your application is bleading ( not managing the memory properly ) or your server is little small for the load that its running..
I am inclined towards the first problem..
second exception is rare to be seen.. it happens when a full garbage collection is run & failed on concurrent modes.. ( this means your pages are latching on to the resources and not releasing them).. to me these two looks connected..
I will be able to tell more if you can give us a little more detail about what your application does..
0
 
atwoodjAuthor Commented:
@Kuldeepchaturvedi...

I'm agree that it is probably a bleeding application that is causing our problem. We are on a shared server and had our JVM heap size doubled but we are still getting the error.

The application is a bit complicated. It's an online stock market and investing simulation for students. It's been developed over the past year by a couple of different java programmers (which may have helped cause a problem in communication).

Students login, create their own company, and answer questions to an array of teacher-selected assignments about their business. Then they each have a portfolio of cash that they can invest in other companies. The share price of each company is affected by the trading that happens. Teachers manage the assignments, news announcements, rules, etc.

We've just had a group of 40 students start using the program. it's one of our first 'large' groups to simultaneously login. They are in the process of answering questions to the assignments. Yesterday in  a 90 minute period we had to restart Tomcat 6 times. Not fun!

I think it started when we had them all login to the application.

Is there any way for me to tell what part of the application and coding might be bleeding and/or not releasing resources as they should?

I'm upping the point value on this because it's a lot deeper than I originally thought and might take a while for us to sort out.

I can post any coding necessary.

Here's a more complete excerpt from the log file if it helps.

+++++korea1396korea1396
korea1396korea1396
[Loaded org.apache.jsp.student.class_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded vss.student.Environments from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/Environments.class]
[Loaded vss.student.CurrentNewsTag from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/CurrentNewsTag.class]
[Loaded java.sql.SQLWarning from /usr/local/jdk1.5.0_06/jre/lib/rt.jar]
[Loaded com.mysql.jdbc.Messages from file:/home2/dluebbe/public_html/WEB-INF/lib/mysql_jdbc.jar]
[Loaded vss.student.Guidelines from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/Guidelines.class]
[Loaded org.apache.jsp.student.bank_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded vss.student.ShowSymbols from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/ShowSymbols.class]
[Loaded vss.student.PriceBean from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/PriceBean.class]
[Loaded java.math.MutableBigInteger from /usr/local/jdk1.5.0_06/jre/lib/rt.jar]
[Loaded sun.reflect.GeneratedConstructorAccessor11 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedConstructorAccessor12 from __JVM_DefineClass__]
peter2peter2
peter2peter2
[Loaded sun.reflect.GeneratedConstructorAccessor13 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedConstructorAccessor14 from __JVM_DefineClass__]
[Loaded org.apache.jsp.teacher.view_005fanswer_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded vss.teacher.TagViewAssignmentsList from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/teacher/TagViewAssignmentsList.class]
[Loaded vss.student.QuestionAnswerBean from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/QuestionAnswerBean.class]
[Loaded vss.student.TradeServlet from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/TradeServlet.class]
[Loaded org.apache.jsp.student.portfolio_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded vss.student.StudentShareTag from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/StudentShareTag.class]
[Loaded vss.student.ShareBean from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/ShareBean.class]
[Loaded vss.student.LoanDepositTag from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/LoanDepositTag.class]
[Loaded org.apache.jsp.student.market_005finfo_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded vss.student.StudentMarketInfoBean from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/StudentMarketInfoBean.class]
[Loaded vss.SharePriceBean from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/SharePriceBean.class]
[Loaded java.text.NumberFormat$Field from /usr/local/jdk1.5.0_06/jre/lib/rt.jar]
daisy2daisy2
[Loaded org.apache.jsp.student.confirmTrade_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded vss.student.ConfirmTradeServlet from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/ConfirmTradeServlet.class]
[Loaded org.apache.jsp.student.create_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Unloading class sun.reflect.GeneratedConstructorAccessor14]
[Unloading class sun.reflect.GeneratedConstructorAccessor13]
[Loaded org.apache.jsp.student.question_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded vss.student.ClassAssignmentsList from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/ClassAssignmentsList.class]
[Loaded org.apache.jsp.student.AssignmentDetail_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded vss.student.AssignTitleTag from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/AssignTitleTag.class]
[Loaded vss.student.AssignmentDetailTag from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/AssignmentDetailTag.class]
[Loaded vss.student.QuestionBean from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/QuestionBean.class]
[Loaded vss.student.AnswerAssignment from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/AnswerAssignment.class]
[Loaded sun.reflect.GeneratedConstructorAccessor15 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedConstructorAccessor16 from __JVM_DefineClass__]
[Unloading class sun.reflect.GeneratedConstructorAccessor15]
[Unloading class sun.reflect.GeneratedConstructorAccessor16]
[Loaded sun.net.ConnectionResetException from /usr/local/jdk1.5.0_06/jre/lib/rt.jar]
lisa2148lisa2148
[Loaded sun.reflect.GeneratedConstructorAccessor17 from __JVM_DefineClass__]
[Loaded org.apache.jsp.student.view_005fanswer_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded vss.student.ViewAssignmentsList from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/ViewAssignmentsList.class]
[Loaded sun.reflect.GeneratedConstructorAccessor18 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedConstructorAccessor19 from __JVM_DefineClass__]
SamKane1992SamKane1992
[Unloading class sun.reflect.GeneratedConstructorAccessor19]
[Unloading class sun.reflect.GeneratedConstructorAccessor18]
emilie007emilie007
emilie007emilie007
[Loaded sun.reflect.GeneratedConstructorAccessor20 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedConstructorAccessor21 from __JVM_DefineClass__]
[Unloading class sun.reflect.GeneratedConstructorAccessor20]
[Unloading class sun.reflect.GeneratedConstructorAccessor21]
Sushi5000Sushi5000
[Loaded org.apache.jsp.demo.Demo.demo_005fframeset_005fwelcome_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded org.apache.jsp.Frames.topNavFrame2_005fwithStyle_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded org.apache.jsp.student.research_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded vss.student.ResearchTag from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/ResearchTag.class]
[Loaded vss.student.CancelTradeServlet from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/CancelTradeServlet.class]
[Loaded sun.reflect.GeneratedConstructorAccessor22 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedConstructorAccessor23 from __JVM_DefineClass__]
SamKane1992SamKane1992
[Unloading class sun.reflect.GeneratedConstructorAccessor22]
[Unloading class sun.reflect.GeneratedConstructorAccessor23]
[Loaded vss.student.LoanDepositBean from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/LoanDepositBean.class]
[Loaded org.apache.jsp.alogin_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded vss.admin.AdminCheck from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/admin/AdminCheck.class]
[Loaded org.apache.jsp.admin.permit_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded vss.admin.TeachersTag from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/admin/TeachersTag.class]
[Loaded sun.reflect.GeneratedConstructorAccessor24 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedConstructorAccessor25 from __JVM_DefineClass__]
[Loaded vss.admin.RunningListTag from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/admin/RunningListTag.class]
[Loaded vss.admin.FinishedListTag from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/admin/FinishedListTag.class]
korea1396korea1396
[Unloading class sun.reflect.GeneratedConstructorAccessor24]
[Unloading class sun.reflect.GeneratedConstructorAccessor25]
[Loaded org.apache.jsp.demo.Tutorial.tutorial_005fframeset_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded org.apache.jsp.demo.Demo.standards_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded org.apache.jsp.learn.contact_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded sun.reflect.GeneratedConstructorAccessor26 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedConstructorAccessor27 from __JVM_DefineClass__]
[Loaded org.apache.jsp.student.StudentInfoB_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded org.apache.jsp.student.IssueConfirm_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Unloading class sun.reflect.GeneratedConstructorAccessor26]
[Unloading class sun.reflect.GeneratedConstructorAccessor27]
[Loaded sun.reflect.GeneratedConstructorAccessor28 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedConstructorAccessor29 from __JVM_DefineClass__]
Sushi5000Sushi5000
evilfamily1evilfamily1
[Loaded org.apache.jsp.student.market_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded vss.student.SShowDates from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/SShowDates.class]
[Loaded vss.student.ShowPrices from file:/home2/dluebbe/public_html/WEB-INF/classes/vss/student/ShowPrices.class]
[Loaded org.apache.jsp.advertising_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
[Loaded org.apache.jsp.demo.Demo.faqs_jsp from file:/usr/local/jakarta-dluebbe/jakarta-tomcat-5.5.7/work/Catalina/studentstockmarket.com/_/]
Pisang57Pisang57
Pisang57Pisang57
ryud51587ryud51587
haenaS2haenaS2
haenaS2haenaS2
Mar 20, 2007 9:11:08 AM org.apache.tomcat.util.threads.ThreadPool$ControlRunnable run
SEVERE: Caught exception (java.lang.OutOfMemoryError: unable to create new native thread) executing org.apache.jk.common.SocketAcceptor@dab859, terminating thread
emilie007emilie007
[Unloading class sun.reflect.GeneratedConstructorAccessor29]
[Unloading class sun.reflect.GeneratedConstructorAccessor28]
emilie007emilie007
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
KuldeepchaturvediCommented:
Wow thats going to be a pretty complex application in my opinion.. By going thru the exception trace, I think its a case of bleeding some where. Also there is a fair chance of sessions getting out of hand.... Can you confirm how the sessions are being used in your app? I mean how much of data is being put in the session by each user..
as far as checking for memory leaks are concern, there are some profiler ( like jprofiler) who can check it out for you but they are costly softwares..
Also can you test the app with less number of users? say 5-8 and see how the app holds up..

Also check how the database access is being managed? is it using connection pools? are the connections being released after every operation? this is the most common problem of the systems when it comes to slow performance and heavy memory uses
check these things and let me know if you find any thing
0
 
atwoodjAuthor Commented:
Our site just crashed as the kids started to login. That leads me to believe it's something with the login procedure.

Does any of the following code look like it could be causing problems?

package vss;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import vss.student.StudentBean;
import vss.ConnectionFactory.ConnectionFactory;
import java.sql.Connection;

public class StudentLoginB extends HttpServlet {

    //Process the HTTP Get request
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException {
        request.setAttribute("option", "forward");
        HttpSession session = request.getSession();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String class_id = null;
        String pass = null;
        String high_pass = null;
        Connection conn = ConnectionFactory.getConn();
        String query =
            "select password, high_password, class_id from student where username='" + username + "'";
        try {
            Statement stmt = conn.createStatement();
            ResultSet rset = stmt.executeQuery(query);
            if (rset.next()) {
                pass = rset.getString(1);
                high_pass = rset.getString(2);
                class_id = rset.getString(3);
                if (!pass.equalsIgnoreCase(password) &&
                    !high_pass.equalsIgnoreCase(password)) {
                    session.setAttribute("ErrorMsg",
                                         "I'm sorry, that is not a valid password.");
                    query = null;
                }else {
                    query = "select s.id, s.name, s.class_id, s.company_name, s.symbol, s.cash, s.deposit" +
                            ", s.dcheck, s.lcheck, s.confirm, s.username, s.email" +
                            ", c.class_name, c.status, c.start_time, c.end_time" +
                            " from student s, class c where s.class_id=" +
                            Integer.parseInt(class_id) + " and s.username='" + username +
                            "' and c.id=" + Integer.parseInt(class_id);
                }
            } else {
                session.setAttribute("ErrorMsg",
                                     "I'm sorry, that is not a valid user name.");
                query = null;
            }
            if (query != null) {
                Enumeration enume = session.getAttributeNames();
                while (enume.hasMoreElements()) {
                    String attrNm = (String) enume.nextElement();
                    if (! (attrNm.equals("country") || attrNm.equals("state") ||
                           attrNm.equals("city"))) {
                        session.removeAttribute(attrNm);
                    }
                }
                rset = stmt.executeQuery(query);
                rset.next();
                StudentBean student = new StudentBean();
                student.setId(rset.getInt("id"));
                String name = rset.getString("name");
                int space = name.indexOf(' ');
                String tmpname = name.substring(space + 1) + " " +
                                 name.substring(0, space);
                student.setName(tmpname);
                student.setPassword(pass);
                student.setHigh_password(high_pass);
                student.setClass_id(rset.getInt("class_id"));
                student.setCompany_name(rset.getString("company_name"));
                student.setSymbol(rset.getString("symbol"));
                student.setCash(rset.getDouble("cash"));
                //student.setDeposit(rset.getDouble("deposit"));
                student.setClass_name(rset.getString("class_name"));
                student.setClassStatus(rset.getInt("status"));
                student.setDcheck("" + rset.getString("dcheck"));
                student.setLcheck("" + rset.getString("lcheck"));
                student.setConfirm(rset.getInt("confirm"));
                if(rset.getString("username")==null ||
                   "null".equalsIgnoreCase(rset.getString("username"))){
                    student.setUsername("");
                }else{
                    student.setUsername("" + rset.getString("username"));
                }
                System.out.println(rset.getString("username") + student.getUsername());
                if(rset.getString("email")==null
                   || "null".equalsIgnoreCase(rset.getString("email"))){
                    student.setEmail("");
                }else{
                    student.setEmail("" + rset.getString("email"));
                }

                String start_date = null;
                String end_date = null;
                if (rset.getDate("start_time") != null) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    start_date = sdf.format(rset.getDate("start_time"));
                }
                if (rset.getDate("end_time") != null) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    end_date = sdf.format(rset.getDate("end_time"));
                }
                student.setGameStartTime(start_date);
                student.setGameEndTime(end_date);

                session.setAttribute("type", "1");
                session.setAttribute("userBean", student);
                if(pass.equalsIgnoreCase("stock"))
                    response.sendRedirect("student/StudentInfoB.jsp");
                else
                    response.sendRedirect("student/class.jsp");
            } else {
                response.sendRedirect("logins.jsp");
            }
        } catch (SQLException sqle) {
            session.setAttribute("noenddate", "noenddate");
            response.sendRedirect("logins.jsp");
        } finally {
            ConnectionFactory.closeConn(conn);
        }
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws
    ServletException, IOException
    {
        doGet(request, response);
    }

}
0
 
KuldeepchaturvediCommented:
This code looks harmless to me.. only trobule that it could have created was not to close the database connection which it is closing in Finally block..

can you post code for class.jsp and student InfoB.jsp?
0
 
atwoodjAuthor Commented:
@Kuldeepchaturvedi
I will post the code for the class.jsp page along with the code for the three .java files that are called when this page is loaded.

Just to help you all understand. This class.jsp page is the main page that each student lands on after logging in. They also return to this page several times while logged in. Which may relate to something that mayankeagle has mentioned and the use of session.setAttribute. I notice in the code for that session.setAttribute is used at least three times each time the class.jsp page is loaded.

Here's my question @mayankeagle: Each time that class.jsp is loaded, is a new object created for each instance of a session.setAttribute call? So even if the same student refreshes the class.jsp page multiple objects are created as session variables that would keep piling up?

I'll post the code in four separate instances.

1. class.jsp
2. CurrentNewsTag.java
3. Environments.java
4. Guidelines.java
0
 
atwoodjAuthor Commented:
Here's the code for class.jsp:

<%@ taglib prefix="student" uri="/WEB-INF/taglib.tld" %>
<html>

      <head>
      <script type="text/javascript" language="JavaScript">
<!-- Copyright 2002 Bontrager Connection, LLC

function getCalendarDate()
{
   var months = new Array(13);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   var now         = new Date();
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   var year        = now.getYear();
   if(year < 2000) { year = year + 1900; }
   var dateString = monthname +
                    ' ' +
                    monthday +
                    ', ' +
                    year;
   return dateString;
} // function getCalendarDate()

function getClockTime()
{
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var ap = "AM";
   if (hour   > 11) { ap = "PM";             }
   if (hour   > 12) { hour = hour - 12;      }
   if (hour   == 0) { hour = 12;             }
   if (hour   < 10) { hour   = "0" + hour;   }
   if (minute < 10) { minute = "0" + minute; }
   var timeString = hour +
                    ':' +
                    minute +
                    " " +
                    ap;
   return timeString;
} // function getClockTime()

//-->
</script>
            <title>Simulation Homepage</title>
          <link href="../css/MainStyle.css" rel="stylesheet" type="text/css">
          <link href="../css/topNavStyle.css" rel="stylesheet" type="text/css">
      </head>

      <body>
            <%@ include file="../Frames/topNavFrame2.jsp" %>
      <!-- Include head and menu -->
      <%
      String value = (String)request.getParameter("pageId");
      if(value != null){
            pageContext.setAttribute("pageId", value);
      }
      %>
      <!-- Content -->
      <% vss.student.StudentBean student = (vss.student.StudentBean)session.getAttribute("userBean");
            pageContext.setAttribute("class_id", ""+student.getClass_id());
      %>
      <div class="pageHeader">
            <%=student.getName()%> :: <%=student.getClass_name()%><br>      
            <script type="text/javascript" language="JavaScript">
                        <!--
                        var calendarDate = getCalendarDate();
                        var clockTime = getClockTime();
                        document.write(calendarDate);
                        document.write(" :: ");
                        document.write(clockTime);
                        //-->
            </script><br>
            Trading starts on <%=student.getGameStartTime() %><br>
            Trading ends on <%=student.getGameEndTime() %>
      </div>      
      
      <div class="pageTitle">
      <h1><%=student.getClass_name()%> simHome </h1>
      <h2>Welcome to the simulation homepage for your class. </h2>
      </div>
      
      
<div id="mainBodyText">      Read through the Environment and Rules & Guidelines sections. Also, regularly check the Bulletin Board for any announcements that may influence your business or investing strategies. </div>

      <table width="96%"border="0" align="center" cellpadding="5" cellspacing="0" class="tableBorder">
      <tr>
            <td width="25%" valign="top">
                  <table width=100% border=0 cellpadding=0 cellspacing=0>
                        <tr>
                              <th>Environment</th>
                        </tr>
                        <tr><td valign="top">
                                                <student:Environments>
                                                </student:Environments>
                        </td>
                    </tr>
              </table>
            </td>
            <td width=75% rowspan=2 valign="top">
                  <table width=100% border=0 cellpadding=0 cellspacing=0>
                        <tr>
                          <th>Bulletin Board</th>
                        </tr>
                        <tr>
                        <td valign="top">
                                    <student:CurrentNewsTag>
                              </student:CurrentNewsTag>
                        </td>
                  </tr>
              </table>
            </td>
      </tr>
      <tr>
            <td valign=top>
                  <table width=100% border=0 cellpadding=0 cellspacing=0>
                        <tr>
                              <th>Rules & Guidelines</th>
                        </tr>
                        <tr>
                        <td valign="top" class="noBorderCell">
                        <student:Guidelines>
                  </student:Guidelines>                        
                        </td>
                        </tr>

              </table>
            </td>
      </tr>
</table>
<p>&nbsp;</p>

</body>
</html>
0
 
atwoodjAuthor Commented:
CurrentNewsTag.java


package vss.student;

import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.util.ArrayList;
import java.sql.*;
import vss.ConnectionFactory.*;
import java.io.IOException;
import vss.TextFormat;

public class CurrentNewsTag
    extends TagSupport {
  private int count;
  private String stime = null;
  private String sdate = null;
  private String content = null;

  public int doStartTag() {
    Connection conn = ConnectionFactory.getConn();
    try {
      String sid = "" + pageContext.getAttribute("class_id");
      int id = Integer.parseInt(sid);
      String query =
          "select time, time, content from bulletinboard where class_id=" +
          id + " order by id desc";
      Statement stmt = conn.createStatement();
      ResultSet rset = stmt.executeQuery(query);
      if (rset.next()) {
        Time time = rset.getTime(1);
        stime = time.toString();
        Date date = rset.getDate(2);
        sdate = date.toString();
        content = rset.getString(3);
      }
    }
    catch (Exception e) {
      System.err.println("vss.student.CurrentNewsTag.doStartTag()");
      System.err.println(e);
    }
    finally {
      ConnectionFactory.closeConn(conn);
    }
    return EVAL_BODY_INCLUDE;
  }

  public int doAfterBody() throws JspException {
    try {
      if (sdate == null) {
        pageContext.getOut().println("There is no news now!");
      }
      else {
        TextFormat.out(pageContext.getOut(), content);
      }
    }
    catch (Exception ioe) {
      System.err.println("vss.student.CurrentNewsTag.doAfterBody()");
      System.err.println(ioe);
    }
    return SKIP_BODY;
  }
}
0
 
atwoodjAuthor Commented:
Environments.java



package vss.student;

import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.util.*;
import java.sql.*;
import vss.ConnectionFactory.*;
import java.io.IOException;
import javax.servlet.http.HttpSession;
import vss.TextFormat;

public class Environments
    extends TagSupport {
  private StudentBean object;
  private String environment = null;

  public int doStartTag() {
    object = (StudentBean) pageContext.getSession().getAttribute("userBean");
    String query = "select environment from class where id=" +
        object.getClass_id();
    Connection conn = ConnectionFactory.getConn();
    try {
      Statement stmt = conn.createStatement();
      ResultSet rset = stmt.executeQuery(query);
      rset.next();
      environment = rset.getString(1);
    }
    catch (SQLException sqle) {
      System.err.println("vss.student.Environments.doStartTag()");
      System.err.println(sqle);
    }
    finally {
      ConnectionFactory.closeConn(conn);
    }
    return EVAL_BODY_INCLUDE;
  }

  public int doAfterBody() throws JspException {
    try {
      boolean flag = false;
      if (environment == null) {
        pageContext.getOut().println(
            "The Environment has not been set!");
      }
      else if (environment.length() > 300) {
        //pageContext.getOut().println(environment.substring(0, 300) + "...");
        TextFormat.out(pageContext.getOut(),
                       environment.substring(0, 300) + "...");
        flag = true;
      }
      else {
        TextFormat.out(pageContext.getOut(), environment);
        //pageContext.getOut().println(environment);
      }
      HttpSession session = pageContext.getSession();
      session.setAttribute("SEnv", environment);
      if (flag) {
        pageContext.getOut().println("<div class=\'readMore\'>");
        pageContext.getOut().println(
            "<a href=\"./fullDesc.jsp\" target=\"_blank\">Read full description...</a>");
        pageContext.getOut().println("</div>");
      }
    }
    catch (Exception e) {
      System.err.println("vss.student.Environments.doAfterBody()");
      System.err.println(e);
    }
    return SKIP_BODY;
  }

}
0
 
atwoodjAuthor Commented:
Guidelines.java


package vss.student;

import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.util.*;
import java.sql.*;
import vss.ConnectionFactory.*;
import java.io.IOException;
import javax.servlet.http.HttpSession;
import vss.TextFormat;

public class Guidelines
    extends TagSupport {
  private StudentBean object;
  private String guideline = null;

  public int doStartTag() {
    object = (StudentBean) pageContext.getSession().getAttribute("userBean");
    String query = "select guideline from class where id=" +
        object.getClass_id();
    Connection conn = ConnectionFactory.getConn();
    try {
      Statement stmt = conn.createStatement();
      ResultSet rset = stmt.executeQuery(query);
      rset.next();
      guideline = rset.getString(1);
    }
    catch (SQLException sqle) {
      System.err.println("vss.student.Guidelines.doStartTag()");
      System.err.println(sqle);
    }
    finally {
      ConnectionFactory.closeConn(conn);
    }
    return EVAL_BODY_INCLUDE;
  }

  public int doAfterBody() throws JspException {
    try {
      /*boolean flag = false;
             if (guideline == null) {
        pageContext.getOut().println("No Guidelines Now!");
             }
             else if (guideline.length() > 300) {
        //pageContext.getOut().println(guideline.substring(0, 300) + "...");
        TextFormat.out(pageContext.getOut(),
                       guideline.substring(0, 300) + "...");
        flag = true;
             }
             else {
        TextFormat.out(pageContext.getOut(), guideline);
        //pageContext.getOut().println(guideline);
             }
             pageContext.getOut().println("</b></font></td></tr>");
       */
      //if (flag) {
      String rules = "1. Each participant will be given $10,000 to invest. Each participant can invest in companies, invest in a Certificate of Deposit (CD) from the bank, take out a loan from the bank, or do nothing at all.\n<br><br>2. No participant will be able to make more than...";
      TextFormat.out(pageContext.getOut(), rules);
      HttpSession session = pageContext.getSession();
      session.setAttribute("SGui", guideline);
      pageContext.getOut().println("<div class=\'readMore\'>");
      pageContext.getOut().println(
          "<a href=\"./fullDesc.jsp\" target=\"_blank\">Read full description...</a>");
      pageContext.getOut().println("</div>");
      //}
    }
    catch (Exception e) {
      System.err.println("vss.student.Guidelines.doAfterBody()");
      System.err.println(e);
    }
    return SKIP_BODY;
  }

}
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> Each time that class.jsp is loaded, is a new object created for each instance of a session.setAttribute call?

Yes
0
 
atwoodjAuthor Commented:
@mayankeagle

...so would that mean that all of these session objects are being created and not destroyed and that this would then cause the server to slow down as more and more of these objects are created?

Additionally, would using request.setAttribute ()  instead of session.setAttribute achieve the same result for the user when they load the class.jsp page? ...but the objects would be destroyed immediately after being served and not pile up?

[Sorry, but I'm very new to this and I have to try to explain this to my programmer, who doesn't speak English as his first language. I have to make sure I fully understand what's going on.]
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> so would that mean that all of these session objects are being created and not destroyed

Yes they remain in the session as long as the user is logged on.

>> that this would then cause the server to slow down as more and more of these objects are created?

Yes because of higher memory usage.

>> would using request.setAttribute ()  instead of session.setAttribute achieve the same result for the user when they load the class.jsp page

Yes.

>> but the objects would be destroyed immediately after being served and not pile up?

Yes again. Your understanding is correct. The objects will be garbage collected when the request object is garbage collected.
0
 
KuldeepchaturvediCommented:
>>Each time that class.jsp is loaded, is a new object created for each instance of a session.setAttribute call?

>>Yes

when you are getting a object from session.. there no new object getting created. It returns ONLY the reference of the object stored in the session ( unless its a primitive type object, i.e. string, interger etc)..
StudentClass is not getting created over & over again in class jsp.. its just getting the reference from session again & again which is trivial in memory uses terms..


However all your tags are connecting to the database and then disconnecting again...
This will lead to a slow performance.. ( in class.jsp the code ends up connecting & disconnecting three times)...
I am not sure how your connectionFactory is implemented but after looking at this code I am fairly certain that there is something fishy going on inside this factory..
Rest of the code looks fairly straightforward & in my opinion is not likely to cause a memory leak anywhere..

oh by the way.. Its one of the worst practice to define methods in a jsp file..(getCalenderDate)!!
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> when you are getting a object from session.. there no new object getting created. It returns ONLY the reference of the object stored in the session

>> its just getting the reference from session again & again

If that code for retrieving the information from the database again if the JSP is hit twice, it is effectively getting it again from the DB and not from the session - depends on whether the application uses this caching from the session or not. atwoodj?

>> which is trivial in memory uses terms..

If many users are logged on and this approach is being followed for many pages, then all session objects will grow with unrequired data....
0
 
KuldeepchaturvediCommented:
>>If that code for retrieving the information from the database again if the JSP is hit twice, it is effectively getting it again from the DB and not from the session - depends on whether the application uses this caching from the session or not. atwoodj?

the studentClass is getting created once in Login procedure and then stored in the session...
If the control is not going back to the login servlet then there is no database access thats happening for student bean..

Yes there are database access on the tags which will slow down the system and I agree with you on that point.. as far as the studentbean is concern..
Given that the control does not return to the login procedure.. its not getting the values from the database again.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> the studentClass is getting created once in Login procedure and then stored in the session...

If all of the student bean's data is required throughout the rest of the application and is being correctly accessed from the session, its fine. My comment was a general, more towards whether this is being followed for retrieving request-specific data through out the application or not.
0
 
atwoodjAuthor Commented:
I will paste the code for connectionFactory below.

@Kuldeepchaturvedi.
You note that there are three connections to the DB being made for each time class.jsp loads. What would be a more efficient way of requesting this information?

@both.
Is it still better to use request.setAttribute than session.setAttribute?

Here's the connectionFactory code:

package vss.ConnectionFactory;

import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class ConnectionFactory {

  static String drivers = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
  static String connString =
      "jdbc:microsoft:sqlserver://localhost:1433;User=XX;Password=XX;DatabaseName=vss";
  static String user_name = "XX";
  static String password = "XX";

  public static void setConnection(String drivers, String connString,
                                   String user_name, String password) throws
      Exception {
    Connection conn = null;
    try {
      Class.forName(drivers);
      conn = DriverManager.getConnection(connString, user_name, password);
      ConnectionFactory.drivers = drivers;
      ConnectionFactory.connString = connString;
      ConnectionFactory.user_name = user_name;
      ConnectionFactory.password = password;
    }
    catch (Exception e) {
      throw new Exception();
    }
    finally {
      if (conn != null) {
        try {
          conn.close();
        }
        catch (Exception e) {}
      }
    }
  }

  public static Connection getConn() {
    try {
      Class.forName(drivers);
      Connection conn = DriverManager.getConnection(connString, user_name,
          password);
      return conn;
    }
    catch (Exception e) {
      System.err.println(
          "Database Error: Call admin to set database information");
    }
    return null;
  }

  public static void closeConn(Connection conn) {
    try {
      conn.close();
    }
    catch (Exception e) {
      System.err.println("Database Error: Cann't stop database connection");
    }
  }

  public static void main(String[] args) throws Exception {
    String id = "4";
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn = DriverManager.getConnection("jdbc:mysql:///vss", "XX", "XX");
    PreparedStatement pstmt = conn.prepareStatement(
        "insert into prices(class_id, student_id, date, price) values(?, ?, ?, ?)");
    pstmt.setInt(1, 1);
    pstmt.setInt(2, 1);
    pstmt.setDate(3, new java.sql.Date(new java.util.Date().getTime()));
    pstmt.setDouble(4, 1.01);
    pstmt.executeUpdate();
  }
}
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> Is it still better to use request.setAttribute than session.setAttribute?

If the data has to be accessed across multiple pages - use session, and then retrieve it from the session using getAttribute () otherwise store it in the request (if it is per page data)
0
 
KuldeepchaturvediConnect With a Mentor Commented:
your connection factory is most probably a culprit of sending system off the memory limit..

Its using a new connection per request to the database ( & almost sure way to a slow performing system)..

Here is what is happening..

1. Every getConnection method loads the database driver, authenticates the user and returns the connection..
on a page in three tags.. this thing happens three time..

every finally section code closes the connection...

2. Every user repeates the same process over and over again...

Now imagine this happening with 40 users in the system..
if they access class.jsp .. you would have created and closed the database connection 120 times...!!!!!!!

change this factory to implement a connection pooling and you should see a remarkable improvement of your applications stabilty and response time..

If you do not know how to do this then let me know..
0
 
Mayank SAssociate Director - Product EngineeringCommented:
BTW why is the connection opened in 3 methods - setConnection (), getConn () as well as main () ? And why is there a main () in a JSP application ;-)
0
 
KuldeepchaturvediCommented:
>>why is there a main () in a JSP application ;-)

most probably the developer was testing the bean and went lazy in deleting it...:-)
0
 
atwoodjAuthor Commented:
@mayan
Thanks for that. I will review our java code to ensure we are using the appropriate coding.

@kuldeep
I'm not sure how to use connection pooling. Can you point me in the right direction?

@mayan again...
I'm not sure why 3 different methods are being used. I didn't code this. We had two guys working on this before I was brought onboard. I think this was a learning experience for them. They are no longer with us and I'm trying to sort this out.

...I don't see where you are referring to a "main ()"? Please help. What can be safely removed?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Thought so, it looks more like a test for the DB connection but it doesn't even test the ConnectionFactory properly if it opens the connection on its own instead of using getConn () etc ;-)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> What can be safely removed?

I think you can comment out and later remove the main (). Is your application calling getConn () or the other method?
0
 
KuldeepchaturvediCommented:
>>I don't see where you are referring to a "main ()"? Please help. What can be safely removed?

both main and setconnection can safely removed. System is not using them..

As far as connection pooling goes... refer to the link below..

http://www.onjava.com/pub/a/onjava/2006/04/19/database-connection-pooling-with-tomcat.html

if you still have questions then let me know..

I suggest that you leave your connectionPool class and the getConnection method in place..
just change how the connection is obtained.
It will save a lot of trouble of changing code everywhere in the system..
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> catch (Exception e) {
>>       throw new Exception();
>>    }

To preserve the stack trace details and original exception information, you might wanna make it:

catch (Exception e) {
      throw e ;
    }

or just remove it altogether and let the try block remain with only a finally.
0
 
KuldeepchaturvediCommented:
One more thing.. the link that I provided does go a little elaborate in defining the DBListener etc.. you really do not need all of it...
just plain Database pool with a JNDI naming...
here is a little simpler version of the same thing
http://www.crazysquirrel.com/computing/java/connection-pooling.jspx
0
 
atwoodjAuthor Commented:
Thanks to both of you for the information. It's been helpful. I need to digest it a bit and have a chat with my programmer. I'll be back in touch shortly.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Sure
0
 
atwoodjAuthor Commented:
Hey...we've done some work but a slight problem I just wanted to ask about.

In our server.xml file we have the code pasted below. My programmer did this but I was wondering what username and password should be included here. Should it be a MySQL user that we've used in the old ConnectionFactory file?

We are getting closer to an answer. Thanks for your help and patience.

   <Host name="studentstockmarket.com" appBase="/home2/dluebbe/public_html">
      <Alias>www.studentstockmarket.com</Alias>
      <Alias>simceo.org</Alias>
      <Alias>www.simceo.org</Alias>
      <Context path="" reloadable="true" docBase="/home2/dluebbe/public_html" debug="1">
      <Resource name="jdbc/simceo" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="root" password="" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql:///vss?autoReconnect=true"/>
      </Context>
      <Context path="/manager" reloadable="true" docBase="/usr/local/jakarta-dluebbe/tomcat/server/webapps/manager" privileged="true" antiResourceLocking="false" antiJARLocking="false"/>
   </Host>
0
 
atwoodjAuthor Commented:
PS. Our catalina.out logged the following:

Database Error: Call admin to set database information
Database Error: Cann't stop database connection
[Loaded clime.messadmin.model.ErrorData from file:/home2/dluebbe/public_html/WEB-INF/lib/MessAdmin-Core-4.0.jar]
Mar 26, 2007 10:29:41 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet StudentLoginB threw exception
java.lang.NullPointerException
      at vss.StudentLoginB.doGet(StudentLoginB.java:31)
      at vss.StudentLoginB.doPost(StudentLoginB.java:132)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at clime.messadmin.filter.MessAdminFilter.doFilter(MessAdminFilter.java:104)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:306)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
      at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:595)
0
 
KuldeepchaturvediCommented:
Yes they should be your Database user id & password.
0
 
KuldeepchaturvediCommented:
>>Database Error: Call admin to set database information
Database Error: Cann't stop database connection

Have you changed the code in your connection factory to use the connection pool?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>>  My programmer did this but I was wondering what username and password should be included here.

Yes you should put them there so that you can change them without modifying the source code in subsequent runs if the database credentials change. If it is in the connection factory class, then it is hard coded in the source code and will need to be re-compiled everytime it changes.
0
 
atwoodjAuthor Commented:
I think so...here's the new connection factory...is it ok?

package vss.ConnectionFactory;

import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
 *
 * <p>Title: ConnectionFactory</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author zhaofeng
 * @version 1.1
 */
public class ConnectionFactory {
    private static DataSource ds=null;
    static{
        Context ctx;
        try {
            ctx = new InitialContext();
            ds = (DataSource)ctx.lookup("java:comp/env/jdbc/simceo");
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static Connection getConn(){
        try {
            if(ds==null)
                throw new Exception("datasource  is  null");
            return ds.getConnection();
        } catch (Exception e) {
            System.err.println(
                    "Database Error: Call admin to set database information");
        }
        return null;
    }

    public static void closeConn(Connection conn) {
        try {
            conn.close();
        } catch (Exception e) {
            System.err.println("Database Error: Cann't stop database connection");
        }
    }
}
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>>  My programmer did this but I was wondering what username and password should be included here.

Yes you should put them there so that you can change them without modifying the source code in subsequent runs if the database credentials change. If it is in the connection factory class, then it is hard coded in the source code and will need to be re-compiled everytime it changes.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Try printing the stack trace of the actual exception in the catch block so that you know what caused it.

catch ( Exception e )
{
  e.printStackTrace () ;

}

Sorry about the double post last time.
0
 
atwoodjAuthor Commented:
Ok...thanks. I've changed the username and password and I'll have the programmer fix the catch block.

My programmer asked me to put mysql_jdbc.jar in the \tomcat\common\lib directory. We currently have it in our WEB-INF\lib directory. Do I need to move it and delete it from the WEB-INF directory, or leave it in both places?

0
 
KuldeepchaturvediCommented:
Looks like this method is blowing up..

public static Connection getConn(){
        try {
            if(ds==null)
                throw new Exception("datasource  is  null");
            return ds.getConnection();
        } catch (Exception e) {
            System.err.println(
                    "Database Error: Call admin to set database information");
        }
        return null;
    }


change it to ..
public static Connection getConn(){
        try {
            if(ds==null)
                throw new Exception("datasource  is  null");
            return (Connection)ds.getConnection();
        } catch (Exception e) {
            System.err.println(
                    "Database Error: Call admin to set database information");
               e.printStackTrace();
        }
        return null;
    }

Mostprobaly it will still bomb.. but we will know why..:-)
0
 
KuldeepchaturvediCommented:
>>
My programmer asked me to put mysql_jdbc.jar in the \tomcat\common\lib directory. We currently have it in our WEB-INF\lib directory. Do I need to move it and delete it from the WEB-INF directory, or leave it in both places?
put it in Tomcat's lib directory...

after you place it there. then you need to stop and start tomcat.. & also you can delete it from web-inf/lib
0
 
Mayank SAssociate Director - Product EngineeringCommented:
If it is in common\lib, all web apps can use it. If it is in WEB-INF\lib, only that project/ web app can use it.
0
 
atwoodjAuthor Commented:
I made the changes to the password and username, reuploaded everything and stop/start the server. Still no luck. I wasn't able to make the changes to the catch block yet. We've just had a group of students start playing the simulation so I can't make any changes for a couple of hours. Until then can I review the connection pool code with you and the steps I followed?

1. I stopped tomcat.
2. I uploaded mysql_jdbc.jar to the /tomcat/common/lib/ directory
3. I deleted mysql_jdbc.jar from the WEB-INF/lib/ directory.
4. I replaced the server.xml file in the /conf/ directory
5. I replaced the web.xml file in the WEB-INF directory
6. I replaced ConnectionFactory.class in the ConnectionFactory directory
7. I restarted the server.

Is this the proper protocol?

I've already posted the new ConnectionFactory.java code and will make the catch block changes.

Our server.xml file was changed to have the proper username and password.

In our web.xml file the following code was added:
  <resource-ref>
         <description>
           Resource reference to a factory for java.sql.Connection
           instances that may be used for talking to a particular
           database that is configured in the server.xml file.
         </description>
         <res-ref-name>
           jdbc/simceo
         </res-ref-name>
         <res-type>
           javax.sql.DataSource
         </res-type>
         <res-auth>
           Container
         </res-auth>
    </resource-ref>

However, I notice we still have this block of code in the web.xml file. Is it necessary?
  <context-param>
    <param-name>ConnectString</param-name>
<param-value>jdbc:microsoft:sqlserver://localhost:1433;User=XX;Password=XX;DatabaseName=vss</param-value>
  </context-param>

Suggestions?
Thanks so much!
0
 
KuldeepchaturvediCommented:
yes these are the correct steps..
If you are using tomcat 5 or above then you can make your context files as separate xml files instead of sticking them in the web.xml which is lot more cleaner way of doing it.
0
 
atwoodjAuthor Commented:
Ok. we changed the catch block and here's the output. What does it mean?! I see that there was a problem using 'root' as the username and no password. I changed the username and pwd to what we used to use in our connectionfactory. Same error. Ideas?

++++++

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Server connection failure during transaction. Due to underlying exception: 'java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)'.

** BEGIN NESTED EXCEPTION **

java.sql.SQLException
MESSAGE: Access denied for user 'root'@'localhost' (using password: NO)

STACKTRACE:

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:770)
      at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3641)
      at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1175)
      at com.mysql.jdbc.Connection.createNewIO(Connection.java:2669)
      at com.mysql.jdbc.Connection.<init>(Connection.java:1474)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:264)
      at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
      at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
      at vss.ConnectionFactory.ConnectionFactory.getConn(ConnectionFactory.java:41)
      at vss.StudentLoginB.doGet(StudentLoginB.java:27)
      at vss.StudentLoginB.doPost(StudentLoginB.java:132)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at clime.messadmin.filter.MessAdminFilter.doFilter(MessAdminFilter.java:104)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:306)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
      at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:595)


** END NESTED EXCEPTION **


Attempted reconnect 3 times. Giving up.)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:855)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
      at vss.ConnectionFactory.ConnectionFactory.getConn(ConnectionFactory.java:41)
      at vss.StudentLoginB.doGet(StudentLoginB.java:27)
      at vss.StudentLoginB.doPost(StudentLoginB.java:132)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at clime.messadmin.filter.MessAdminFilter.doFilter(MessAdminFilter.java:104)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:306)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
      at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.SQLException: Server connection failure during transaction. Due to underlying exception: 'java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)'.

** BEGIN NESTED EXCEPTION **

java.sql.SQLException
MESSAGE: Access denied for user 'root'@'localhost' (using password: NO)

STACKTRACE:

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:770)
      at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3641)
      at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1175)
      at com.mysql.jdbc.Connection.createNewIO(Connection.java:2669)
      at com.mysql.jdbc.Connection.<init>(Connection.java:1474)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:264)
      at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
      at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
      at vss.ConnectionFactory.ConnectionFactory.getConn(ConnectionFactory.java:41)
      at vss.StudentLoginB.doGet(StudentLoginB.java:27)
      at vss.StudentLoginB.doPost(StudentLoginB.java:132)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at clime.messadmin.filter.MessAdminFilter.doFilter(MessAdminFilter.java:104)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:306)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
      at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:595)


** END NESTED EXCEPTION **


Attempted reconnect 3 times. Giving up.
      at com.mysql.jdbc.Connection.createNewIO(Connection.java:2734)
      at com.mysql.jdbc.Connection.<init>(Connection.java:1474)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:264)
      at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
      at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
      ... 24 more
Database Error: Call admin to set database information
java.lang.NullPointerException
      at vss.ConnectionFactory.ConnectionFactory.closeConn(ConnectionFactory.java:52)
      at vss.StudentLoginB.doGet(StudentLoginB.java:125)
      at vss.StudentLoginB.doPost(StudentLoginB.java:132)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at clime.messadmin.filter.MessAdminFilter.doFilter(MessAdminFilter.java:104)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:306)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
      at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:595)
Database Error: Cann't stop database connection
[Loaded clime.messadmin.model.ErrorData from file:/home2/dluebbe/public_html/WEB-INF/lib/MessAdmin-Core-4.0.jar]
Mar 27, 2007 10:21:16 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet StudentLoginB threw exception
java.lang.NullPointerException
      at vss.StudentLoginB.doGet(StudentLoginB.java:31)
      at vss.StudentLoginB.doPost(StudentLoginB.java:132)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at clime.messadmin.filter.MessAdminFilter.doFilter(MessAdminFilter.java:104)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:306)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
      at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:595)
0
 
KuldeepchaturvediCommented:
have you started the server after changing the user id & pwd?
0
 
KuldeepchaturvediCommented:
so I assume everything is good now...:-)
0
 
atwoodjAuthor Commented:
Kul
It's getting there. We are trying to implement the connection pool, but have had a few difficulties with the programming. I will probably open a new question if the latest solution doesn't work. I felt this question had drifted away from what I originally asked...so it was better to close it and move on to something more focused.

Thanks for all of your help. You may be hearing from me soon.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.