Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Question on Object [] args parameter in SimpleJdbcTemplate.query method

  1. #1
    Join Date
    Aug 2007
    Posts
    13

    Default Question on Object [] args parameter in SimpleJdbcTemplate.query method

    Greetings,

    I have a question on the Object [] args parameter of the SimpleJdbcTemplate's query method -

    What impact does setting the arguments have on the query that is executed? The API docs only describe them as "the args for the query".

    Thanks,
    Steve

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    What impact does setting the arguments have on the query that is executed?
    ?, about performance???

    i dont think that 3 objects in the query can make some critical problem in the performance, and 10?

    why did you ask this??
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I'm not entirely sure I understand the question. If you query has parameters then the args are used to fill in the parameter placeholder e.g. SELECT * from my_table WHERE my_id = ?. This is a general JDBC thing.
    Last edited by karldmoore; Aug 27th, 2007 at 02:11 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  4. #4
    Join Date
    Aug 2007
    Posts
    13

    Default

    Ok, so what you're saying is that they are for Prepared Statements - that makes sense then. Are you aware of a resource/documentation that confirms this?

    Thanks.

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    The reference manual has information on this and a quick look at the code confirms this.
    http://static.springframework.org/sp...c-JdbcTemplate
    Last edited by karldmoore; Aug 27th, 2007 at 02:11 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  6. #6
    Join Date
    Aug 2007
    Posts
    13

    Default

    Thanks - I appreciate it.

  7. #7
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote Originally Posted by smm View Post
    Thanks - I appreciate it.
    Not a problem, the reference manual is well worth have a look at. There's lots of useful information there!
    Last edited by karldmoore; Aug 27th, 2007 at 02:11 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  8. #8
    Join Date
    Aug 2006
    Location
    Now Germany, previously Ukraine
    Posts
    1,546

    Default

    Quote Originally Posted by karldmoore View Post
    Not a problem, the reference manual is well worth have a look at. There's lots of useful information there!
    While thing seems to self-obvious and reference manual is a good thing to look in, I have to note that Javadoc on this matter is definitely subpar. Probably, worth a JIRA.

    Regards,
    Oleksandr

  9. #9
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote Originally Posted by al0 View Post
    While thing seems to self-obvious and reference manual is a good thing to look in, I have to note that Javadoc on this matter is definitely subpar. Probably, worth a JIRA.
    If you feel there's an issue JIRA it away .
    Last edited by karldmoore; Aug 27th, 2007 at 02:10 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  10. #10
    Join Date
    Jan 2009
    Posts
    3

    Talking Smm was right... I'll submit the JIRA

    So I ran into this issue. I looked at the API. pass in a single Object parameter, it works. Pass in an Array of a single parameter it works too. Can't be both as both are definitely NOT the same thing. So which is it? API implies and explicitly says variable arguments meaning 1,2,3.... not int[]{1,2,3} or even int[]{1,2,3,4}.

    Inquisitive about this, I did a quick experiment. I added another bind parameter to my query and now passed in the API mandated 1,2 Result? No fortune cookie for me! Now I pass in int[]{1,2} and Voilla!

    So you see, the array is the right one. The variable argument list is just a side effect of the way they translate your parameters behind the scenes. Whatever it is they are doing, I can check or speculate but doesn't matter only works for the first parameter. Point is the API is wrong and documentation \ javadoc should be updated. In my case, my initial problem was complicated by the fact that I was dealing with Oracle dates and that's a PITA all in itself. After getting completely puzzled why it wont work, I fired up sql plus and wrote and ran equivalent query just for a sanity check. It worked fine. Hey who needs Spring when we have sql plus? So cut it down to a sigle parameter and it worked. I added another one with the array and was even more confused why it worked. Then I realized what was going on. Searched online found this thread.

    Hope that helps others who get confused by this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •