Solved

Spring JDBCTemplate - Incrementing ID column .

Posted on 2013-11-15
3
560 Views
Last Modified: 2014-01-21
All,

I have an id column which is not set as Auto increment . We have to manaully increment it everytime we insert a record like this (select max([ERRORKEY]) from ERROR_LOG_TEMP])+ 1

Is there a way I can auto generate it during every insert using Spring JDBC template ??
0
Comment
Question by:FranklinRaj22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Expert Comment

by:jb1dev
ID: 39655049
Given a table foo with columns a, b, c, id (where "id" is the column to increment) can you not do something like:

                    INSERT INTO foo 
                       (a, b, c, id) 
                     VALUES (?, ?, ?, 
                       (SELECT IFNULL(MAX(id), 0) + 1 FROM foo) 
                     ) 

Open in new window

0
 
LVL 14

Accepted Solution

by:
jb1dev earned 500 total points
ID: 39655053
That IFNULL() I think is specific to MySQL and we use it to handle the case of the first insert into the table where there are zero rows and hence the nested select statement would return null, we need to coalesce that null value to a 0.
For other database equivalents of that function, see:
http://www.w3schools.com/sql/sql_isnull.asp
0
 

Author Comment

by:FranklinRaj22
ID: 39667648
ok
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mapShare challenge 13 147
Modeling a class in java 5 67
jdbc error in jsp application 20 74
ejb example issues 3 53
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question