pro_jsp thread: javax.servlet.ServletException: Invalid argument value: Duplicate entry '0' for key 1
It might be possible that you're getting a Primary Key Violation,
because this would throw an Exception, put a try/catch block around
you're executeUpdate, that might work.
Good luck
Bart Laeremans
----- Original Message -----
From: Richard Tham <richardtham@m...>
Date: Tuesday, July 10, 2001 6:03 am
Subject: [pro_jsp] javax.servlet.ServletException: Invalid argument
value: Duplicate entry '0' for key 1
> I got the above error msg.
> Pls help :)
>
> My JSP coding is as follows:
>
> <html>
> <head>
> <title>
> Successful Update of Patient Medicine Prescription
> </title>
> </head>
> <%@ page language="java" import="java.sql.*" %>
> <body>
>
> <%
>
> Class.forName("org.gjt.mm.mysql.Driver");
>
> String id3 = request.getParameter("id2");
> String prescrip2 = request.getParameter("prescrip");
> String quantity2 = request.getParameter("quantity");
> String illtype2 = request.getParameter("illtype");
>
>
> Connection myConn =
> DriverManager.getConnection("jdbc:mysql:///clinic");
> Statement stmt = myConn.createStatement();
>
>
> int rowsAffected = stmt.executeUpdate("insert into inventory
> (id,prescrip,quantity) values('" + id3 +"','" + prescrip2 +"','" +
> quantity2 + "')");
>
> int rowsAffected2 = stmt.executeUpdate("insert into medical
> (illtype)
> values('" + illtype2 + "')");
>
>
> if (rowsAffected == 1)
> {
> %>
> <h1>Successful Update of Patient Medicine Prescription</h1>
> Thank you Update of Patient Medicine Prescription.
> <p>
> See all patients<br>
>
> Go back to control center
>
> <% }
> else
> {
> %>
> <h1>Sorry, addition has failed.</h1>
> Go back to control center
> <%
> }
> stmt.close();
> myConn.close();
> %>
> </body>
> </html>
>
>
> And my DB file creation is as follows:
>
> create table patient (
> id float(30) not null,
> name varchar(30) not null,
> age int(2) not null,
> address varchar(30),
> phone float(30) not null,
>
> primary key(id)
> );
>
>
>
> create table inventory (
> id int(12) not null,
> prescrip varchar(30) not null,
> quantity varchar(10) not null,
>
> primary key(id)
> );
>
>
> create table medical (
> id int(12) not null,
> illtype varchar(50) not null,
>
> primary key(id)
> );
>
>
> create table visit (
> id int(12) not null,
> vno int(10) not null,
> vdate int(15) not null,
>
> primary key(id)
> );
>