Using Spring JDBC Support to Get Outputs

I am using Spring JDBC support to run SQL queries and updates on an Oracle database. I would like to insert a row and then get the key that was assigned (using Oracle sequence). In normal JDBC code, I would include the RETURNING INTO clause and then register the output parameter ( well described here )

However, I would like to just use Spring to handle all my JDBC work for me. For non-integrated SQL statements, I am currently using the MapSqlParameterSource object and registering all of my props. Can I also register an output parameter like this and return it to me? I looked at part 11 of the Spring docs section and I saw that there was support for an output parameter if I use stored procedures, but I would like to avoid that if possible. Thank you.

+2


source to share


2 answers


I don't think the Spring JDBC Support API provides explicit support for OUT parameters, so you might need to step back a bit and use the more general Query API provided by JdbcTemplate

:

Object execute(PreparedStatementCreator psc, PreparedStatementCallback action)

      



This allows arbitrary JDBC operations to be performed within the Spring-managed connection and PrepatedStatement

. The downside is that handling and tidyup things like ResultSets

becomes your problem.

+1


source


Check this code - it might do what you want, not sure if Oracle supports this syntax.



getReturnedGeneratedKeys () Spring JDBC Example

0


source







All Articles