1 message in com.mysql.lists.javaSQLException: Duplicate key or integr...
FromSent OnAttachments
Wayne Marrison18 Jun 2004 02:43 
Subject:SQLException: Duplicate key or integrity constraint violation, message from server: "Duplicate entry 'null' for key 1"
From:Wayne Marrison (way@wmcomputing.com)
Date:06/18/2004 02:43:30 AM
List:com.mysql.lists.java

Hi List,

My first time here, so I hope I don't upset anyone.

I'm fairly new to Java (as in very new) but have used mysql for a long time now. Currently using Java 1.4.2, netbeans 3.6 and connector 3 on both Linux (suse 9) and win32.

MySQL version on win32 is : 4.1.2alpha Linux : 4.0.15

Both have the same problem.

I have created a table as follows:

CREATE TABLE header ( ID int(10) unsigned NOT NULL auto_increment, ClusterID varchar(40) NOT NULL default '', TStamp datetime NOT NULL default '0000-00-00 00:00:00', SoftwareVersion varchar(20) NOT NULL default '', Capacity bigint(32) unsigned NOT NULL default '0', Freespace bigint(32) unsigned NOT NULL default '0', ReplicaAddress varchar(32) NOT NULL default '', ReadAllowed varchar(5) NOT NULL default '0', WriteAllowed varchar(5) NOT NULL default '0', PurgeAllowed varchar(5) NOT NULL default '0', DeleteAllowed varchar(5) NOT NULL default '0', ExistAllowed varchar(5) NOT NULL default '0', ClipEnum varchar(5) NOT NULL default '0', RetentionPeriod bigint(16) unsigned NOT NULL default '0', SupportedSchemes varchar(100) NOT NULL default '', PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

And am trying to insert a record using :

String SQL = "insert into Header (ClusterID,TStamp,SoftwareVersion,Capacity,Freespace,ReplicaAddress,ReadAllo wed,WriteAllowed,PurgeAllowed,DeleteAllowed,ExistAllowed,ClipEnum,RetentionP eriod,SupportedSchemes) values ('" + getClusterID() + "','" + TStamp.getTime() + "','" + getVersion() + "'," + getCapacity() + "," + getFreeSpace() + ",'" + getReplicaAddress() +"','" + getCapability("read","allowed") +"','" + getCapability("write","allowed") +"','" + getCapability("purge","allowed") + "','" + getCapability("delete","allowed") + "','" + getCapability("exist","allowed") + "','" + getCapability("clip-enumeration","allowed") + "'," + getCapability("retention","default") +",'" + getCapability("blobnaming","supported-schemes") + "')";

System.out.println(SQL);

stmt.executeUpdate(SQL, Statement.RETURN_GENERATED_KEYS);

And this is the error returned:

SQLException: Duplicate key or integrity constraint violation, message from server: "Duplicate entry 'null' for key 1" SQLState: 23000 VendorError: 1062

When I check back at the table - the insert has completed ok, but of course the program fails and does not continue with the rest of the code.

I have searched the newsgroups for answers, but the only one that has anything similar is this one, but with no follow up since about 2nd June ( http://lists.mysql.com/java/7539 ).

Any help would be much appreciated.

Many thanks

Wayne