DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7637>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7637

Tomcat terminates after connecting to a database

           Summary: Tomcat terminates after connecting to a database
           Product: Tomcat 3
           Version: 3.3.1 Final
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Critical
          Priority: Other
         Component: Webapps
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


I am running Win2K with SP2 applied and the latest version of MDAC (2.7). When 
I run a test page that connects to a database, does a query and outputs the 
results, the page is displayed with the correct results but I then receive the 
message "The instruction at '0x1f9c6bce' referenced memory at '0x1f9c6bce'. The 
memory could not be 'read' (This is a java.exe application error). Following 
this Tomcat terminates. Exactly the same code can be put into a java class and 
run from command line without any problems. If the class is called from a JSP 
run by Tomcat, the same error occurs.
Database:SQLServer2000 and Access2000

Microsoft standard ODBC drivers used
SQLSRV32.DLL Version 2000.81.7713.00
ODBCJT32.DLL Version 4.00.6019.00
All MDAC components have been tested using the Microsoft ComCheck.exe component 
checker. All tested as being OK with no conflicts.
Browser is Microsoft IE6.0

Have been using JDK1.2.2 to allow jk_nt_service.exe to work correctly but same 
issue occurs with JDK1.4.

Eventviewer does not give any other information than the above error.

The following is tha java class that does the connection and queries:

import java.sql.*;

public class FruitConnect {

   private Driver drv = null;
   private Connection conn = null;
   private ResultSet rs = null;
   private Statement stmt = null;


   public FruitConnect(){}

   public void dbConnect() throws Exception{
      drv = (Driver) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance
();
      conn = DriverManager.getConnection
("jdbc:odbc:Fruit","fruit_login","fruit_login");
   }

   public boolean getNextItem() throws Exception{
      boolean ret = rs.next();
      return(ret);
   }

   public String getItemNameString(String columnName) throws Exception{
      String name = rs.getString(columnName);
      return(name);
   }

   public float getItemNameFloat(String columnName) throws Exception{
      float name = rs.getFloat(columnName);
      return(name);
   }

   public boolean selectFruits() throws Exception{
      String query = "SELECT Id, Name FROM Fruit";
      stmt = conn.createStatement();
      rs = stmt.executeQuery(query);
      boolean ret = false;
      if (rs != null)
         ret = true;
      return(ret);
   }

   public boolean selectMonths() throws Exception{
      String query = "SELECT Id, Name FROM Month";
      stmt = conn.createStatement();
      rs = stmt.executeQuery(query);
      boolean ret = false;
      if (rs != null)
         ret = true;
      return(ret);
   }

   public boolean selectFruitForSale() throws Exception{
      String query = "SELECT F.Name AS Fruit, M.Name AS Month, Price, Weight, 
(Price * Weight) AS TotalPrice FROM FruitMonth AS FM, Fruit AS F, Month AS M 
WHERE FM.FruitId = F.Id AND FM.MonthId = M.Id ORDER BY M.Id";
      stmt = conn.createStatement();
      rs = stmt.executeQuery(query);
      boolean ret = false;
      if (rs != null)
         ret = true;
      return(ret);
   }

   public int insertFruit(String name) throws Exception{
      String query = "INSERT INTO Fruit (Name) VALUES ('" + name + "')";
      stmt = conn.createStatement();
      int ret = stmt.executeUpdate(query);
      return(ret);
   }

   public int insertFruitForSale(String insertValues) throws Exception{
      String query = "INSERT INTO FruitMonth (FruitId, MonthId, Price, Weight) 
VALUES (" + insertValues + ")";
      stmt = conn.createStatement();
      int ret = stmt.executeUpdate(query);
      return(ret);
   }

   public int deleteFruit(String fruitList) throws Exception{
      String query = "DELETE FROM Fruit WHERE Name IN (" + fruitList + ")";
      stmt = conn.createStatement();
      int ret = stmt.executeUpdate(query);
      return(ret);
   }

   public void dbDisconnect() throws Exception{
      stmt.close();
      conn.close();
   }

}

The following is the JSP that calls the class:

   <%@ page import="java.sql.*" %>
   <jsp:include page="adminHeader.html" flush="true" />

   <div align="center">
   <table border="1" cellspacing="2" cellspacing="2" width="150">
   <tr>
     <th>Fruit</th>
   </tr>

   <% FruitConnect fruitConnect = new FruitConnect(); %>
   <%
   int counter = 0;
   String bgColor = "";
   String mode = request.getParameter("mode");
   if ( mode == null )
   mode = "view";

   fruitConnect.dbConnect();
   if (fruitConnect.selectFruits()) {
   while (fruitConnect.getNextItem()) {
   //alternate the background color of the rows for readability
     if ((counter % 2) == 0){
       bgColor = "#6464FF"; 
     } else {
       bgColor = "#FFFFFF";
     } 
     String fruitName = fruitConnect.getItemNameString("Name");
     %>
     
     <form method="post" action="delFruit.jsp">
     <tr bgcolor="<%= bgColor %>">
       <td align="left">
         <% if (mode.equals("delete")) {%>
           <input type="checkbox" name="delFruit" value="<%=fruitName %>">
         <% } %>
         <%= fruitName %>
       </td>
     </tr>

     <%

   counter = counter + 1;
   }
     
   if (mode.equals("delete")) {
   %>
     <tr>
       <td><input type="submit" name="submit" value="Delete Checked
   Fruit"></td>
     </tr>
   <% 
   }
   }
   fruitConnect.dbDisconnect();
   %>
   </form>
   </table>
   </div>
   <jsp:include page="adminFooter.html" flush="true" />

The same class can be called from command line without problem using a simple 
stub.

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to