Skip to content
Advertisement

Reuse a parameter in a PreparedStatement?

I am passing a parameter to a PreparedStatement like this :

And the query looks like this :

Now I want to modify my query like this, and reuse the first parameter (both ? would use the runId parameter) :

Is that possible without doing this :

Advertisement

Answer

This cannot be done with plain JDBC. You could instead use Spring’s JDBCTemplate, which would support what you want with Named Parameters, and re-use the same name wherever it’s needed in the statement.

See Named parameters in JDBC

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement