Home Answers Viewqa JDBC Detecting Duplicate Keys

 
 


Clark
Detecting Duplicate Keys
1 Answer(s)      2 years and 7 months ago
Posted in : JDBC

Detecting Duplicate Keys I have a program that inserts rows in a table. My table has a column 'Name' that has a unique constraint. If the user attempts to insert a duplicate name into the table, I want to display an error message by processing the error code from the database. How can I capture this error code in a Java program?

View Answers

November 15, 2010 at 11:41 AM


Hi friends,

A solution that is perfectly portable to all databases, is to execute a query for checking if that unique value is present before inserting the row. The big advantage is that you can handle your error message in a very simple way, and the obvious downside is that you are going to use more time for inserting the record, but since you're working on a PK field, performance should not be so bad. You can also get this information in a portable way, and potentially avoid another database access, by capturing SQLState messages. Some databases get more specific than others, but the general code portion is 23 - "Constraint Violations". UDB2, for example, gives a specific such as 23505, while others will only give 23000.

Thanks.









Related Pages:
Detecting Duplicate Keys
Detecting Duplicate Keys  Detecting Duplicate Keys I have a program that inserts rows in a table. My table has a column 'Name' that has a unique constraint. If the user attempts to insert a duplicate name into the table, I want
Reading duplicate keys from .properties file - Development process
Reading duplicate keys from .properties file  Hi, I am reading... will not allow duplicate keys, but still I want to develope a program to identify the duplicate keys and print it on console. It is urgent requirement,please reply
Detecting the file extension
Detecting the file extension   How to detect the file extension in PHP?   Read the given tutorial to detect the file extension in PHP. The fileexists() function, fileexists php, file_exists in php
java.sql.BatchUpdateException: Duplicate entry '135-16448' for key 1 - Hibernate
java.sql.BatchUpdateException: Duplicate entry '135-16448' for key 1  ...; num keys: 10 00:34:38,229 DEBUG NewPooledConnection:304.... java.sql.BatchUpdateException: Duplicate entry '135-16448' for key 1
setting keys
setting keys  Hi Sir\Mam,At present we are doing Payroll Project .I would like to set some special keys for my forms and i want the coding to do the same .Pls Provide me source code for setting keys as soon as possible
Keys in DBMS
Keys in DBMS  Whats the main difference between composite and super keys   Difference between super key and composite key: A super key... in a table while composite key is the combination of two or more than two keys
detecting browser time zone - Java Interview Questions
detecting browser time zone  Hi! Is it possible to detect the user browser time zone that means his country. if possible please let me know how to do it... thanks in advance
Error is: Generated keys not requested.
Error is: Generated keys not requested.   Hi, Following error is coming in my program. Error is: Generated keys not requested. You need to specify... = conn.prepareStatement(queryInsert,Statement.RETURN_GENERATED_KEYS); Thanks
Java duplicate elements
Java duplicate elements  Which class has no duplicate elements
PHP duplicate file - PHP
PHP duplicate file   i wanted to duplicate a PHP file resides in different directory on submission
PHP list array keys
array_keys() function returns the keys of the the given array. It returns the keys in the form of array. Example of PHP list Array Keys <?php...;   $key=array_keys($ar1);     print_r($key); ?>
javascript duplicate value
javascript duplicate value  In javascript how to find the duplicate or variable that contains same value for example ...two different variables contains the same URL Link.    //To loop through use this $("a:contains
duplicate records inserting
duplicate records inserting  in the application i have provided the text filed on entering and submit the record is getting inserted. my question is i want to avoid duplicate values getting inserted. ex. i am inserting name
Duplicate name in Manifest - Struts
Duplicate name in Manifest   Hello I'm facing the following error... java.util.jar.Attributes read WARNING: Duplicate name in Manifest: Depends-On. Ensure that the manifest does not have duplicate entries, and that blank lines separate individual
how to create customise shortcut keys in jsp?
how to create customise shortcut keys in jsp?  I want to use shortcut keys in my application. keys like' EX: 1)S-Slag 2)ex-Exposure etc
Spring Duplicate submit - Spring
Spring Duplicate submit  hi, i have problem in spring, i am pressing back or refresh my request get submitted again what i can do to avoid this,i am using only spring not struts
Get information about foreign keys used in a table.
Get information about foreign keys used in a table.  How can I get information about foreign keys used in a table
Sql query Duplicate
Sql query Duplicate  I have a Employee table with duplicate ID values. How can I find out duplicate records?   Hello Friend, We have... 3 D Delhi Then we have used the following query to find the duplicate data
Remove duplicate values
Remove duplicate values  i am trying to insert values into database from excel spreadsheet .am doing it using JDBC.connected both excel and sql.... q1. how can i eliminate duplicate values during insertion? please i need code
Mysql Find Duplicate Records
Mysql Find Duplicate Records       Mysql Find Duplicate Records is used to find the duplicate Records... 'Mysql Find Duplicate Records'. To grasp and understand example, the select
JavaScript duplicate string
JavaScript duplicate string...; We can create a strings duplicate string with the use of JavaScript's duplicate method. In this example code we have called the duplicate method on the text
JavaScript duplicate method
JavaScript duplicate method       JavaScript's duplicate method creates a duplicate copy of the specified text range. In this example code we have called the duplicate
get information about foreign keys - JDBC
get information about foreign keys  How to get the information about foreign keys in Java
sorting an array of string with duplicate values - Java Beginners
string with duplicate values  How to check the string with duplicate values
JSlider disabling sliding through arrow keys
JSlider disabling sliding through arrow keys  I want that JSlider should not moved by using arrow keys. Is it possible? then guide me please.   Please visit the following links: http://www.roseindia.net/java/example
Duplicate name in Manifest - JSP-Servlet
Duplicate name in Manifest   Hello, I don't have the classpath... WARNING: Duplicate name in Manifest: Depends-On. Ensure that the manifest does not have duplicate entries, and that blank lines separate individual sections
Java arraylist duplicate elements search
Java arraylist duplicate elements search  hi, please help me finding the no of duplicates elements in an arraylist example an arraylist contains elements like: mac raj mohan frank mac tom raj mohan frank result: mac 2 raj
how to validate duplicate records in struts1
how to validate duplicate records in struts1  Hi, After submitting the form i have to validate the email id. If already exists in database i have to display an error message saying that email id already exist
how to validate duplicate records in struts1
how to validate duplicate records in struts1  Hi, After submitting the form i have to validate the email id. If already exists in database i have to display an error message saying that email id already exist
SimpleJdbcInsert, Retrieving auto-generated keys
SimpleJdbcInsert, Retrieving auto-generated keys The auto-generated keys can be generated using "usingGeneratedKeyColumns" method. The name of the auto generated key column can be specified by passing it's name to method
JDBC : Duplicate records in a table
JDBC : Duplicate records in a table In this tutorial, you will learn how to find the duplicate records in a table. Duplicate records in a table : You can check for duplicate records of table. You can group record by any of fields
Write the Keys and Values of the Properties files in Java
Write the Keys and Values of the Properties files in Java... will learn how to add the keys and it's values of the properties files in Java. You know the properties files have the the keys and values of the properties files
I determine where a given table is referenced via foreign keys.
I determine where a given table is referenced via foreign keys.  How can I determine where a given table is referenced via foreign keys
why set doesn't allow duplicate value
why set doesn't allow duplicate value  HI Everyone Any one can help me why set not allowed duplicate value in java. Please post ur comment, its urgent. Thanks in advance
sorting an array of string with duplicate values - Java Beginners
sorting an array of string with duplicate values  I have a sort method which sorts an array of strings. But if there are duplicates in the array it would not sort properly
Get All Keys and Values of the Properties files in Java
Get All Keys and Values of the Properties files in Java... how to get all keys and it's values of the properties files in Java. Java provides the features to collection of all keys and values of the properties file
Get All Keys and Values of the Properties files in Java
Get All Keys and Values of the Properties files in Java... to get all keys and values of the properties files in the Java. This section illustrates the way for getting all keys and corresponding values of the properties
avoid duplicate values using struts - Struts
avoid duplicate values using struts  How to avoid the duplicate values in Struts?  IN action class you check before storeing itSee howFirst your storing data and database data both you check using any method and help
Need to Remove Duplicate Records from Excel Sheet
Need to Remove Duplicate Records from Excel Sheet  Need to Remove Duplicate Records from Excel Sheet. I have one excel sheet having two fields (EmpNum, Rating) have to save in another excel sheet with unique empnum of latest
Remove duplicate characters from the string
Remove duplicate characters from the string In this tutorial, you will learn how to remove duplicate characters from the string. Java has provide several.... Here we are going to remove duplicate characters from the string
Write Keys and Values to the Properties file in Java
Write Keys and Values to the Properties file in Java... how to write keys and values in the properties files through the Java program. The program for writing keys and values to the properties file has been mentioned
Validating Duplicate Entry To Database - Java Beginners
Validating Duplicate Entry To Database  I have a servlet that adds data to the table called foodtype in (Ms Access). i already have Chinese, vegetarian entered in table. what am trying to do is to validate when entering foodtypes
how to display duplicate elements with out using collection Frame work?
how to display duplicate elements with out using collection Frame work?  how to display duplicate elements with out using collection Frame work
JavaScript array remove duplicate
JavaScript array remove duplicate   ... the duplicate elements by creating a user defined function. Since there is not any built-in method in the JavaScript array to remove duplicate elements
how to count unique and duplicate values from one table in mysql?
how to count unique and duplicate values from one table in mysql?  I have use EMP table.I want to count unique and duplicate records from emp table and how to use in java program
PHP Remove Duplicate Values
PHP Array Remove Duplicate Values In PHP if we need to remove duplicate values... an array and returns another array without duplicate values. General.... Return Value Another array without duplicate values  
How to create a duplicate buffer of a long buffer in java.
How to create a duplicate buffer of a long buffer in java. In this tutorial, we will see how to create a duplicate buffer that shares the content of long....  abstract LongBuffer duplicate() The duplicate
Introduction to Map and SortedMap Interface
for storing elements without containing duplicate keys. It allows you to store pairs... is an object that maps keys to values. It is not an extension of the collection interface... to one value. Thus the keys in a map must be unique. The Map interface

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.