473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to display duplicate entry

hii i´m learning jsp and html with sql and i´m beginer on it,
i have the table andcodes below in mysql and jsp, i´m working on html and jsp with netbeans IDE 3.6. of course if i try to insert any thing into that table 2. time, i get a error message: java.sql.SQLException: Invalid argument value: Duplicate entry......

and i want to display that duplicate value with some warning message (value is already exist or something like that)
can any one help me on it, how to do that?????
regards

1-sql codes;
Expand|Select|Wrap|Line Numbers
  1. create table team
  2.             (team_id int not null AUTO_INCREMENT,
  3.             team_fahrer_name VARCHAR (80),
  4.             team_arbeiter_name VARCHAR (80),
  5.             team_fahrzeug_kenntzeichen VARCHAR (80),
  6.             team_beschreibung VARCHAR (80),
  7.             PRIMARY KEY (team_id),
  8.             UNIQUE KEY team_fahrer_name (team_fahrer_name),
  9.             UNIQUE KEY team_arbeiter_name (team_arbeiter_name),
  10.             UNIQUE KEY team_fahrzeug_kenntzeichen (team_fahrzeug_kenntzeichen))TYPE = INNODB;
  11.  
2-javabean;
Expand|Select|Wrap|Line Numbers
  1. public void neuenteam_einfuegen(){
  2.  
  3.         String fahrer_name = this.getfahrer_name();
  4.         String arbeiter_name = this.getarbeiter_name();
  5.         String fahrzeug_kennzeichen = this.getfahrzeug_kenntzeichen();
  6.         String fahrt_typ = this.getfahrt_typ();
  7.  
  8.             dbop= new DBOperationen();
  9.             dbop.dbverbindung();
  10.         String sql="insert into team (team_fahrer_name, team_arbeiter_name, team_fahrzeug_kenntzeichen, team_beschreibung) values ";
  11.         sql+="(\""+fahrer_name+"\",\""+arbeiter_name+"\",\""+fahrzeug_kenntzeichen+"\",\""+fahrt_typ+"\");";
  12.         System.out.println(sql);
  13.         dbop.executeupdate(sql);
  14.  
Feb 21 '09 #1
2 3908
chaarmann
785 Expert 512MB
just make a try-catch statement around your "dbop.executeupdate(sql); " statement. Inside the catch-part, print your warning message.

Be aware that all different errors are thrown that you need to care about in your catch-statement, like the database is down, or the network connection is blocked etc.). So just to test for duplicate primary keys, there is another way:
1.) lock the database table for writing
2.) inquire if one of the primary keys is already there (select * from team where team_fahrer_name=... or team_arbeiter_name=... or ...).
3.) if you get some records (=results) back, then print a warning only. Else, that means if there is no record returned, execute your update-statement.
4.) unlock database
Feb 23 '09 #2
@chaarmann
thanx thanx thanx,
solved the problem
Feb 24 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: marx | last post by:
I have a bit of a problem and any help would be much appreciated. Problem: I have two dropdown list boxes with same data(all data driven). These are used for two separate entries. For every...
4
by: sri2097 | last post by:
Hi all, I'm storing number of dictionary values into a file using the 'cPickle' module and then am retrieving it. The following is the code for it - # Code for storing the values in the file...
1
by: Joseph Chase | last post by:
I am running version 4.1.13a-log on a Mac XServe. How can I receive a 'duplicate entry' error for an UPDATE? An update isn't creating an entry, so why this error message? ...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
8
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on...
3
emandel
by: emandel | last post by:
In my DB I have an Events Table, a Participants table, and a attendance table. The attendance table is the junction table that connects the other two (many to many). So in the attendance tale, I...
5
by: baur79 | last post by:
Hi guys i try to run this code in loop and to pass even the entry is duplicated def email_insert_in_db(email): sql="INSERT INTO emails (email) values ('%s') "%(email)...
1
by: chicago1985 | last post by:
I have a unique constraint in my Oracle table for 3 fields. If I enter duplicate info on the table using Oracle client I will get an Ora message error ORA-00001 that tells me it is a duplicate entry...
4
by: AXESMI59 | last post by:
have a project in which I am entering Serial Numbers and Date codes into a Combo box. Serial numbers are all different. However, they could each have the same Date Code. Each Serial Number has a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.