I am working on a book example Java Server pages in easy steps. The last chapter talks through creating a JSP online shop using jsp together with mySQL and tomcat. I am experiencing the following error everytime I run the jsp
"Class org.gjt.mm.mysql.PreparedStatement not found"
The class below - Please help!!
<%@ page language="java" contentType="text/html" import="ShoppingBasket
,Product, java.util.*, java.sql.*, java.sql.PreparedStatement, java.math.*,
java.text.*, java.lang.Object" errorPage="errorpage.jsp"%>
<jsp:useBean id="basket" class="ShoppingBasket" scope="session"/>
<html><head><title> Welcome to the Shop </title></head>
<body >
<%
//1. Load the mySql jdbc driver
Class.forName("org.gjt.mm.mysql.Driver"
;
//2. open a coonectin to the "shop" database
java.sql.Connection connection = java.sql.DriverManager.getConnection
("jdbc:mysql://localhost/shop"
;
//3. Assign SQL query and column pattern to variable
String query = "INSERT INTO orders VALUES ('', ? , ? , ? , ? , ? , ? , ? , ? ) " ;
//4. create a statement object for sending SQL queries
java.sql.PreparedStatement Stmt=connection.prepareStatement(query);
//5 get all form attribute values from the request header and insert them
//into the Statement object in the defined pattern...
Stmt.setString(1,request.getParameter("firstname"
);
Stmt.setString(2,request.getParameter("surname"
);
Stmt.setString(3,request.getParameter("address"
);
Stmt.setString(4,request.getParameter("city"
);
Stmt.setString(5,request.getParameter("postcode"
);
Stmt.setString(6,request.getParameter("card_number"
);
Stmt.setString(7,request.getParameter("card_type"
);
Stmt.setString(8,request.getParameter("totalvalue"
);
//6. Add record to the mysql "orders table"
Stmt.executeUpdate();
//7. get an order number incremented from the last order
long order_id = ((org.gjt.mm.mysql.PreparedStatement)Stmt).getLastInsertID();
//8. assign SQL query and column pattern variable
String order_info_query = "INSERT INTO order_info VALUES (' ' ,?,?,?)";
//9. retrieve a list of basket contents from bean
Enumeration products = basket.getProducts();
//10. add record for each different selected item to the mysql "order_info
//table..."
while (products.hasMoreElements()) {
Product product = (Product)products.nextElement();
Stmt = connection.prepareStatement(order_info_query);
Stmt.setLong(1,order_id);
Stmt.setInt(2,Integer.parseInt(product.getID()));
Stmt.setInt(3,product.getQuantity());
Stmt.executeUpdate();
}
//11. clean up all the objects
Stmt.close(); connection.close();
//12. Empty the shopping basket
basket.emptyBasket();
%>
Thanks for your order. It will be processed within 24 hours.<br/>
Please note that your Order Number is No:
<%= order_id %> <br/><>br/
<a href="<%= response.encodeURL("shop-products.jsp"
%>">
<img src="images\toshop.gif" border="0"></a>
</body>
</html>
"Class org.gjt.mm.mysql.PreparedStatement not found"
The class below - Please help!!
<%@ page language="java" contentType="text/html" import="ShoppingBasket
,Product, java.util.*, java.sql.*, java.sql.PreparedStatement, java.math.*,
java.text.*, java.lang.Object" errorPage="errorpage.jsp"%>
<jsp:useBean id="basket" class="ShoppingBasket" scope="session"/>
<html><head><title> Welcome to the Shop </title></head>
<body >
<%
//1. Load the mySql jdbc driver
Class.forName("org.gjt.mm.mysql.Driver"
//2. open a coonectin to the "shop" database
java.sql.Connection connection = java.sql.DriverManager.getConnection
("jdbc:mysql://localhost/shop"
//3. Assign SQL query and column pattern to variable
String query = "INSERT INTO orders VALUES ('', ? , ? , ? , ? , ? , ? , ? , ? ) " ;
//4. create a statement object for sending SQL queries
java.sql.PreparedStatement Stmt=connection.prepareStatement(query);
//5 get all form attribute values from the request header and insert them
//into the Statement object in the defined pattern...
Stmt.setString(1,request.getParameter("firstname"
Stmt.setString(2,request.getParameter("surname"
Stmt.setString(3,request.getParameter("address"
Stmt.setString(4,request.getParameter("city"
Stmt.setString(5,request.getParameter("postcode"
Stmt.setString(6,request.getParameter("card_number"
Stmt.setString(7,request.getParameter("card_type"
Stmt.setString(8,request.getParameter("totalvalue"
//6. Add record to the mysql "orders table"
Stmt.executeUpdate();
//7. get an order number incremented from the last order
long order_id = ((org.gjt.mm.mysql.PreparedStatement)Stmt).getLastInsertID();
//8. assign SQL query and column pattern variable
String order_info_query = "INSERT INTO order_info VALUES (' ' ,?,?,?)";
//9. retrieve a list of basket contents from bean
Enumeration products = basket.getProducts();
//10. add record for each different selected item to the mysql "order_info
//table..."
while (products.hasMoreElements()) {
Product product = (Product)products.nextElement();
Stmt = connection.prepareStatement(order_info_query);
Stmt.setLong(1,order_id);
Stmt.setInt(2,Integer.parseInt(product.getID()));
Stmt.setInt(3,product.getQuantity());
Stmt.executeUpdate();
}
//11. clean up all the objects
Stmt.close(); connection.close();
//12. Empty the shopping basket
basket.emptyBasket();
%>
Thanks for your order. It will be processed within 24 hours.<br/>
Please note that your Order Number is No:
<%= order_id %> <br/><>br/
<a href="<%= response.encodeURL("shop-products.jsp"
<img src="images\toshop.gif" border="0"></a>
</body>
</html>