Detecting Duplicate Keys

Ads

 
 

Share on Google+Share on Google+

Clark
Detecting Duplicate Keys
1 Answer(s)      6 years and 10 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?

Ads
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.


Ads









Related Tutorials/Questions & Answers:
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
Advertisements
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
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
Generate Keys
Generate Keys  hello i need code to generate key , after that send Keys to email address user. for example if you member in your website,if member not having Secret Keys not can download files if member having secret key i
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
duplicate values
duplicate values  My database having cursor that has duplicate values.i want to remove duplicate values through java application
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
JTable duplicate values in row
JTable duplicate values in row  JTable duplicate values in row
Java duplicate elements
Java duplicate elements  Which class has no duplicate elements
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
PHP duplicate file - PHP
PHP duplicate file   i wanted to duplicate a PHP file resides in different directory on submission
Version of com.noodlesandwich>rekord-keys dependency
List of Version of com.noodlesandwich>rekord-keys dependency
Version of com.datomic>s3-access-keys dependency
List of Version of com.datomic>s3-access-keys dependency
Version of com.noodlesandwich>rekord-keys dependency
List of Version of com.noodlesandwich>rekord-keys dependency
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
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); ?>
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
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
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
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
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
sorting an array of string with duplicate values - Java Beginners
string with duplicate values  How to check the string with duplicate values
Maven Dependency s3-access-keys >> 0.1.4
You should include the dependency code given in this page to add Maven Dependency of com.datomic >> s3-access-keys version0.1.4 in your project
Maven Dependency s3-access-keys >> 0.1.6
You should include the dependency code given in this page to add Maven Dependency of com.datomic >> s3-access-keys version0.1.6 in your project
Maven Dependency rekord-keys >> 0.3
You should include the dependency code given in this page to add Maven Dependency of com.noodlesandwich >> rekord-keys version0.3 in your project