Forums Register Login

how can I use LIKE expression on JdbcTemplate?

1
+Pie Number of slices to send: Send
First of all hi to ervey one!
The problem is this: i have a



So the probklem is that I can't do the query.

It throws an SQLException

org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [SELECT * FROM Guitarra WHERE numeroSerie LIKE '?' AND modelo LIKE '?' AND numeroCuerdas LIKE '?' AND nueva LIKE '?' AND color LIKE '?' AND precio LIKE '?' AND fabricante LIKE '?' AND maderaAnterior LIKE '?' AND maderaPosterior LIKE '?' AND tipo LIKE '?']; Parameter index out of range (1 > number of parameters, which is 0).; nested exception is java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:106)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
.
.
.

So how can I use the like expression to do this "SELECT * FROM guitarra WHERE numeroSerie LIKE '%21' AND color LIKE '%' AND numeroCuerdas LIKE '%';" but using in Java in JdbcTemplate??

By the way i'm trying to build a query to search by specific fields I mean, if someone searches a guitar "azul" and 12 cuerdas, this query should work, so what do you recommend me to do??

Greetings and thanks!!

+Pie Number of slices to send: Send

@Override
public List<Book> searchBooks() {
@SuppressWarnings("unchecked")
List<Book> list=
jdbcTemplate.query("select bid,bname,author from book where author like ? or bid like ? "
,new String[]{"%Man%","%BCA%"}
,new RowMapper() {

@Override
public Object mapRow(ResultSet rs, int arg1) throws SQLException {
Book book=new Book();
book.setBid(rs.getString(1));
book.setBname(rs.getString(2));
book.setAuthor(rs.getString(3));
return book;
}
});
return list;
}
How do they get the deer to cross at the signs? Or to read this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 18019 times.
Similar Threads
Batching Select Statements in JDBC
Using Like in preparedstatement
Unit testing StoredProcedure with HSQLDB
MySQL Problem !!!
Data type mismatch need to convert string to a number
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:14:38.