aspose file tools*
The moose likes JDBC and the fly likes how can I use LIKE expression on JdbcTemplate? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how can I use LIKE expression on JdbcTemplate?" Watch "how can I use LIKE expression on JdbcTemplate?" New topic
Author

how can I use LIKE expression on JdbcTemplate?

andy brave
Greenhorn

Joined: Apr 28, 2011
Posts: 1
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!!

lakshman siva
Greenhorn

Joined: Apr 29, 2011
Posts: 1

@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;
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how can I use LIKE expression on JdbcTemplate?
 
Similar Threads
Batching Select Statements in JDBC
Data type mismatch need to convert string to a number
Using Like in preparedstatement
Unit testing StoredProcedure with HSQLDB
MySQL Problem !!!