Announcement Announcement Module
Collapse
No announcement yet.
Question on Object [] args parameter in SimpleJdbcTemplate.query method Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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??

    Comment


    • #3
      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, 02:11 PM.

      Comment


      • #4
        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.

        Comment


        • #5
          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, 02:11 PM.

          Comment


          • #6
            Thanks - I appreciate it.

            Comment


            • #7
              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, 02:11 PM.

              Comment


              • #8
                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

                Comment


                • #9
                  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, 02:10 PM.

                  Comment


                  • #10
                    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.

                    Comment


                    • #11
                      You definitely can profit yourself from learning of Java basics.
                      Just look how Java handles varargs - this handling is not Spring-specific by any means.

                      Java language specification, 3rd edition, chapter 8.4.2 states:
                      Code:
                      If the last formal parameter is a variable arity parameter of type T, it is considered
                      to define a formal parameter of type T[].
                      So what you have observed is behavior dictated by language specification -no more, no less.

                      Regards,
                      Oleksandr
                      Originally posted by pgathua View Post
                      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.

                      Comment

                      Working...
                      X