Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Invalid argument value, message from server: "Duplicate entry '0' for key 1

843836Apr 22 2004 — edited Apr 23 2004
Hi All,

I am working through a shoping cart tutorial using JSP,JDBC and java beans.

I get the following error when trying to write an order to a mysql database.

Invalid argument value, message from server: "Duplicate entry '0' for key 1"

Could this be related to the way I have set up my orders table?

It is set up like this :

order_id varchar(10)
firstName mediumtext
surname mediumtext
address text
city mediumtext
postcode varchar(8)
cardnumber float(16,0)
card_type text
total_order_value tinyint(6)




When the table is empty I get to the confirmed order page if I input a card number without name and address.
When I try any information as a second order I get the duplicate entry error message.

Any help appreciated.

The JSP page is shown below.


Jim Ascroft

<%@ page language="java" contentType="text/html"%>
<%@ page import="java.sql.*,java.util.*,com.bloodoo.ShoppingBasket,com.bloodoo.Product "%>

<%@ page errorPage="errorpage.jsp" %>

<jsp:useBean id="basket" class="com.bloodoo.ShoppingBasket" scope="session"/>

<html>
<head> <title>Your Order Has Been Received</title> </head>
<body>

<%
Class.forName("org.gjt.mm.mysql.Driver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:mysql://localhost/shop");

String query = "INSERT INTO orders VALUES ('',?,?,?,?,?,?,?,?)";
java.sql.PreparedStatement statement = connection.prepareStatement(query);

statement.setString(1,request.getParameter("firstname"));
statement.setString(2,request.getParameter("surname"));
statement.setString(3,request.getParameter("address"));
statement.setString(4,request.getParameter("city"));
statement.setString(5,request.getParameter("postcode"));
statement.setString(6,request.getParameter("card_number"));
statement.setString(7,request.getParameter("card_type"));
statement.setString(8,request.getParameter("totalvalue"));

statement.executeUpdate();


long order_id = ((com.mysql.jdbc.Statement) statement).getLastInsertID();


String order_info_query = "INSERT INTO order_info VALUES ('',?,?,?)";

Enumeration products = basket.getProducts();
while(products.hasMoreElements())
{
Product product = (Product)products.nextElement();
statement = connection.prepareStatement(order_info_query );
statement.setLong(1,order_id);
statement.setInt(2,Integer.parseInt(product.getId()));
statement.setInt(3,product.getQuantity());
statement.executeUpdate();
}

statement.close();
connection.close();
basket.emptyBasket();
%>

Thanks for your order. It will be processed within 24 hours.
Please note that your Order Number is No: <%= order_id %>


<a href=" <%= response.encodeURL(shop-products.jsp") %">">
<img src="images\toshop.gif" border="0" alt="Return to the Shop"></a>



</body>
</html></a>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 21 2004
Added on Apr 22 2004
6 comments
221 views