troubleshooting Question

Problems retrieving the autogenerated key with Oracle and Spring using SimpleJdbcDaoSupport

Avatar of CarlosScheidecker
CarlosScheidecker asked on
JavaJava EEJava App Servers
13 Comments1 Solution2332 ViewsLast Modified:

The following code works perfectly with MySQL versions 5.1 and 5.5. When I run it I can get the autogenerated field value with keyholder.

However, when I do the same agains an Oracle 10 database it returns null.

I do not wish to rewrite the whole thing with prepared statements instead.

So, anyone had the same issue with SimpleJdbcDaoSupport on Spring and Oracle?

public long insertCustomer(Customer aCustomer) {
		long result = -1;
		SqlParameterSource parameterSource = new BeanPropertySqlParameterSource(aCustomer);
		KeyHolder keyholder = new GeneratedKeyHolder();
		try {
			result = getSimpleJdbcTemplate().getNamedParameterJdbcOperations()
					.update(insertCustomerSQL, parameterSource, keyholder);

			if (result > -1) {
				result = keyholder.getKey().longValue();
		} catch (Exception e) {
			// e.printStackTrace();
		return result;
Join our community to see this answer!
Unlock 1 Answer and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros