I have an arraylist which for eg has 12 elements but i need to pass just 6 elements each time to prepared statement.. i m not able to figure out the logic.
Raghavan Muthu wrote:Are you struck with extracting 6 elements or passing only 6 elements to PreparedStatement?
i m struck with both... i have an arraylist for which i know i need to pass 6 elements each time to the preparedstatement and then execute the preparedstatement.. then pass another 6 elements repeat the process.
Seems straight forwards to me! Loop through the array pulling out six values at a time and feed them to the prepared statement. What is the problem?
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32612
4
posted
0
Pull out six values, and print them to screen. Then you have six values. Then you can feed them to the statement. Don't try to do everything all in one stage.
Looks straight forward- But has a catch because the process has to be continued until the elements of the list have been exhausted- One has to remember the last index, repeat the loop to complete all the elements of the list. You would have to first identify number of iterations so that you can completely traverse the list. And for each iteration you need to use the old index and then get the element from the list, increment the index.
Mohamed Sanaulla wrote:Looks straight forward- But has a catch because the process has to be continued until the elements of the list have been exhausted- One has to remember the last index, repeat the loop to complete all the elements of the list. You would have to first identify number of iterations so that you can completely traverse the list. And for each iteration you need to use the old index and then get the element from the list, increment the index.
Is this all required for doing the OP's problem? It is dependent on "what 6 values" he needs. Then he can set those values to PreparedStatement and get his work done. Isnt it?
Raghavan Muthu wrote:
Is this all required for doing the OP's problem? It is dependent on "what 6 values" he needs. Then he can set those values to PreparedStatement and get his work done. Isnt it?
With what information OP has provided- I concluded that the retrieval is sequential
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32612
4
posted
1
I also thought he meant the first 6 elements. Of course, if you read the List interface documentation, you find there is a much simpler way to do it.
Campbell Ritchie wrote:I also thought he meant the first 6 elements. Of course, if you read the List interface documentation, you find there is a much simpler way to do it.
Yeah yeah,got it. Much simpler
divya kundapur
Ranch Hand
Joined: Aug 21, 2007
Posts: 110
posted
0
Mohamed Sanaulla wrote:
Campbell Ritchie wrote:I also thought he meant the first 6 elements. Of course, if you read the List interface documentation, you find there is a much simpler way to do it.
Yeah yeah,got it. Much simpler
thanks a lot Mohamed Sanaulla ,i used the loop you provided and it worked .. just now checked the list interface as said by Campbell Ritchie n there is subList method ... thanks a lot both of you and to this great javaranch
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32612
4
posted
0
I had forgotten about subList, until a few hours ago. It shows you need to go through the API and look which methods are available.