aspose file tools*
The moose likes Java in General and the fly likes Pass 6 elements of arraylist to prepared stmt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Pass 6 elements of arraylist to prepared stmt" Watch "Pass 6 elements of arraylist to prepared stmt" New topic
Author

Pass 6 elements of arraylist to prepared stmt

divya kundapur
Ranch Hand

Joined: Aug 21, 2007
Posts: 110
Hi,

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.

any help


SCJP - 5.0
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Are you struck with extracting 6 elements or passing only 6 elements to PreparedStatement?


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
divya kundapur
Ranch Hand

Joined: Aug 21, 2007
Posts: 110
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.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

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: 39396
    
  28
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.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

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.



Alternatively- You can create an ArrayList of ArrayList where each ArrayList will have an ArrayList of only 6(what ever number) of elements.


Mohamed Sanaulla | My Blog
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

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.



Alternatively- You can create an ArrayList of ArrayList where each ArrayList will have an ArrayList of only 6(what ever number) of elements.


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?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

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: 39396
    
  28
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.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

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
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: 39396
    
  28
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.
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Thats great. subList() is a really a great feature
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pass 6 elements of arraylist to prepared stmt