Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class org.gjt.mm.mysql.PreparedStatement not found

Status
Not open for further replies.

kilo2

Programmer
Jan 2, 2003
3
GB
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=&quot;java&quot; contentType=&quot;text/html&quot; import=&quot;ShoppingBasket
,Product, java.util.*, java.sql.*, java.sql.PreparedStatement, java.math.*,
java.text.*, java.lang.Object&quot; errorPage=&quot;errorpage.jsp&quot;%>

<jsp:useBean id=&quot;basket&quot; class=&quot;ShoppingBasket&quot; scope=&quot;session&quot;/>

<html><head><title> Welcome to the Shop </title></head>

<body >



<%
//1. Load the mySql jdbc driver

Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;);

//2. open a coonectin to the &quot;shop&quot; database
java.sql.Connection connection = java.sql.DriverManager.getConnection
(&quot;jdbc:mysql://localhost/shop&quot;);


//3. Assign SQL query and column pattern to variable
String query = &quot;INSERT INTO orders VALUES ('', ? , ? , ? , ? , ? , ? , ? , ? ) &quot; ;



//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(&quot;firstname&quot;));
Stmt.setString(2,request.getParameter(&quot;surname&quot;));
Stmt.setString(3,request.getParameter(&quot;address&quot;));
Stmt.setString(4,request.getParameter(&quot;city&quot;));
Stmt.setString(5,request.getParameter(&quot;postcode&quot;));
Stmt.setString(6,request.getParameter(&quot;card_number&quot;));
Stmt.setString(7,request.getParameter(&quot;card_type&quot;));
Stmt.setString(8,request.getParameter(&quot;totalvalue&quot;));

//6. Add record to the mysql &quot;orders table&quot;
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 = &quot;INSERT INTO order_info VALUES (' ' ,?,?,?)&quot;;

//9. retrieve a list of basket contents from bean
Enumeration products = basket.getProducts();

//10. add record for each different selected item to the mysql &quot;order_info
//table...&quot;

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=&quot;<%= response.encodeURL(&quot;shop-products.jsp&quot;) %>&quot;>
<img src=&quot;images\toshop.gif&quot; border=&quot;0&quot;></a>


</body>
</html>
 
Hi kilo2:

You must have the mysql driver jar in the system (or the tomcat) classpath.

classpath=%CLASSPATH%;mysqljdbcdriver.jar

You can download it from


To see a discussion about how to set the enviroment variables, you can check this thread:

thread269-440814

Hope it helps.

Pedro Andrés Solorzano
Pontificia Universidad Javeriana
Bogotá, Colombia, SurAmérica.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top