This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Using bind variables in Spring

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing some testing that involves database access using spring framework. I understand that I can create a query using a single bind variable using the following statement:

int countOfActorsNamedJoe = this.jdbcTemplate.queryForInt(
"select count(*) from t_actor where first_name = ?", "Joe");

I'm trying to use the queryForObject implementation described in the Spring docs (url at bottom). I have two questions about this. First I'm trying a simple implementation like this:



But it's giving me an error under queryForObject saying

The method queryForObject(String, Object[], RowMapper) in the type JdbcTemplate is not applicable for the arguments (String, String, ActorMapper)



So my first question is how do I get that working?

My second question is how do I use multiple bind variables? Let's say I wanted to say

SELECT * FROM actors WHERE first_name = XXX AND last_name = YYY"



How would I do that?

Thanks

http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/jdbc/core/JdbcTemplate.html#queryForObject%28java.lang.String,%20java.lang.Object[],%20java.lang.Class%29
 
Ranch Hand
Posts: 686
Netbeans IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The signature is queryForObject(String, Object[], RowMapper)

So you have to pass



Multiple variables
 
J Miller
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You were absolutely right, thanks for the help. Another tip that I found is this: I then tried using LIKE rather than = using this:



This also threw me an error. Apparently you can't use '?%', you have to change it to something like this:


Thanks for the help!
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic