Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC Detecting Duplicate Keys
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


Advertisement
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 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
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
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
duplicate values
duplicate values  My database having cursor that has duplicate values.i want to remove duplicate values through java application
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
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
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); ?>
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
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
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
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
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
get information about foreign keys - JDBC
get information about foreign keys  How to get the information about foreign keys in Java
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
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
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
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
Advertisements
 

 

 

DMCA.com