EdgeCase
EdgeCase

Reputation: 4827

JDBC - Reuse Bind Variable in Query

I have a SQL stmnt like the one below, and it it complaining because I am not passing in two bind variables.

Is there a way I can reuse the one bind variable, since they're the same?

String sqlText = "SELECT * FROM person WHERE (name = UPPER(?) OR name = LOWER(?) )";

List<obj> results = tmplt.query(sqlText, new Object[]{name}, new objExtractor());

Upvotes: 1

Views: 2277

Answers (1)

JB Nizet
JB Nizet

Reputation: 691635

Yes. Use NamedParameterJdbcTemplate and assign the same name to both parameters:

SELECT * FROM person WHERE (name = UPPER(:param) OR name = LOWER(:param) )

More explanations on how to use this class in the documentation.

Upvotes: 7

Related Questions