[ACCEPTED]-Using a variable instead of a parameter index with a JDBC prepared statement-jdbc
Standard JDBC PreparedStatements don't have 2 this ability. Spring JDBC provides this 1 functionality through NamedParameterJdbcTemplate
.
As kd304 mentioned in the comment to my 3 posting, this is a very nice solution if 2 you don't want to incorporate another 3rd 1 party library (like Spring) into your project: Javaworld Article: Named Parameters for PreparedStatement
Using a raw PreparedStatement, this is not 11 possible, as you say. It is possible with 10 CallableStatement, but that requires a stored 9 procedure rather than just a SQL statement.
ORM 8 layers like Hibernate also provide named 7 parameter substitution, and Hibernate also 6 allows you to execute native SQL, bypassing 5 the OR mapping functionality completely.
So 4 if you were really keen to use named parameters, you 3 could employ Hibernate as a way of doing 2 this; you'd only be using a tiny fraction 1 of its functionality.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.