View Single Post
  #1 (permalink)  
Old March 8th, 2004, 06:16 PM
Javahead Javahead is offline
Registered User
 
Join Date: Mar 2004
Location: Luton, Beds, United Kingdom.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default problems with examples

Hi,
    i tried to run the program written on chapter 13 in page 492. i wrote a similar program but if i run it, it shows error. can anyone help me please.Here's my code:

package com;

import java.sql.*;

public class mysql1
 {

  int id=0;
  int account_no=0;
  String pass="";

  public void init()
   {
      Connection con = null;
      Statement st = null;
      ResultSet rs = null;

    try
     {
       Class.forName("com.mysql.jdbc.Driver").newInstance ();
       con = DriverManager.getConnection("jdbc:mysql:///password",
        "root", "firehouse");

       st = con.createStatement();
       rs = st.executeQuery("SELECT id, account_no, password FROM pass");

       while(rs.next())
        {
         id = rs.getInt(1);
         account_no = rs.getInt(2);
         pass = rs.getString(3);
         //System.out.println(userId + ". " + lastName + ", " + firstName + " ");
        }

     } catch (Exception e)
        {
         System.err.println("Exception: " + e.getMessage());
        }
       finally
       {

         try
          {

            if(rs != null)
              rs.close();
            if(st != null)
              st.close();
            if(con != null)
              con.close();
          } catch (SQLException e)
             {
             }
       }
   }

 public int getId()
  {
    return id;
  }

 public int getAccountNo()
  {
    return account_no;
  }
 public String getPass()
  {
    return pass;
  }

 }// class ends


jsp page:

<html>
 <head>
   <title>Checking pass</title>
 </head>
<body>
<%
  com.mysql1 qdb = new com.mysql1();
  qdb.init();

%>
<h2>Query Result</h2>
Id:<%qdb.getPass()%></br>
Account No: <%qdb.getAccount_no()%>
Password: <%qdb.getPass()%>

</body>

</html>


but i get the following error when i run it:

org.apache.jasper.JasperException: Unable to compile class for JSP
No Java compiler was found to compile the generated source for the JSP.
This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK
to the common/lib directory of the Tomcat server, followed by a Tomcat restart.
If using an alternate Java compiler, please check its installation and access path.

    org.apache.jasper.compiler.DefaultErrorHandler.jav acError(DefaultErrorHandler.java:128)
    org.apache.jasper.compiler.ErrorDispatcher.javacEr ror(ErrorDispatcher.java:348)
    org.apache.jasper.compiler.Compiler.generateClass( Compiler.java:415)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:455)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:439)
    org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:555)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:300)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:293)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:240)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:856)

Reply With Quote