Hi, all

Sorry,  if  my question has already been asked.

I have run a JDBC example from Book "Developing JAVA Enterprise Application
" by Stephen Asbury and Scott R. Weiner, chapter 3, pp 22-23. But there is
an error information from Internet Explorer as follows

Error: 500
Internal Servlet Error:

java.lang.ClassCastException: Example
at com.sun.web.core.ServletWrapper.loadServlet(ServletWrapper.java:100)
at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:119)
at com.sun.web.core.InvokerServlet.service(InvokerServlet.java:168)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:155)
at com.sun.web.core.Context.handleRequest(Context.java:414)
at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:139)


In the system control, I have set the ODBC source file according to what
has been described in the book, i.e. using ACCESS database driver and the
data source name is inventory, the location of database name is in the
driver\java\jdbc\inv.mdb. Then I starts the server from jswdk1.0 and try to
run Example.class (in my computer, there is an Access program). There is an
error just above. I don't know what I have done wrong. The source code is as
follows

import java.sql.*;

public class Example
{
    public static void main (String args[])
    {
        try
   {
        /*
          Load the JDBC-ODBC bridge,
          it will register itself with DriverManager.
        */
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch (Exception e)
        {
            System.out.println("JDBC-ODBC driver failed to load.");
            return;
        }

        try
        {
    /*
           Pass the url to the DriverManager.
           It should find our driver and return a database
           connection to an ODBC data source called "inventory".
         */

             Connection con =3D3D
              DriverManager.getConnection("jdbc:odbc:inventory","","");

    // Create a statement and use it to execute a query.
    Statement stmt =3D3D con.createStatement();

        /*
          This returns a resultset.
          We will assume it is not null for simplicity.
        */
      ResultSet rs =3D3D
          stmt.executeQuery("SELECT * FROM Inventory ORDER BY price");

        /*
          In order to determine the type and amount of data returned
          by our query we access the metadata of the result set.
        */
  ResultSetMetaData rsmd =3D3D rs.getMetaData();

        /*
          From the meta data we determine how many columns were
          actually returned.
        */
  int numberOfColumns =3D3D rsmd.getColumnCount();
  int rowCount =3D3D 1;

        /*
          We will loop through the result set printing out
          values for each row.
        */
  while (rs.next())
  {
   for (int i =3D3D 1; i <=3D3D numberOfColumns; i++)
   {
    System.out.print(rs.getString(i)+" ");
   }
   System.out.println("");
   rowCount++;
  }

  // We are done with the Statment so we close it.
  stmt.close();

       // We are done with our connection so we close it.
  con.close();
    } catch (Exception e) {
      System.out.println(e);
    }
  }
}


HS

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to