Results 1 to 12 of 12

Thread: Array Concept

  1. #1
    sandeep43 is offline Member
    Join Date
    May 2011
    Posts
    97
    Rep Power
    0

    Default Array Concept

    Hi all,

    I Have a sql which will retrieve many rows,

    all i want is how to store these each and every value what is retrieved at each loop in an array and later use each and value in array that is stored in different loop.

    only thing i know is i have to use global array. in this concept array is off type String.

    How to accomplish this?

    Regards
    Sandeep
    Last edited by sandeep43; 08-04-2011 at 08:03 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    only thing i know is i have to use global array.
    First think seriously about whether you really should make an array in the first place - after all the information already exists and is accessible in the database and you would be making a second copy. This may be useful, or it may not.

    Another thing to think about is whether you should use an array or some implementation of the List interface.

    The array need not be global. Rather it should available to whatever method needs it. If both the method populating the array and the one accessing it are methods of the same class, then an instance variable is enough. If they are in different classes then the class that populates the array should provide a getter method.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by sandeep43 View Post
    only thing i know is i have to use global array. in this concept array is off type String.
    Can you tell us why you think it has to be 'global' (there are no global variables in Java). Also, why do you think you have to use an array?

    kind regards,

    Jos

    edit: even early in the morning I'm too slow, *sigh* ...
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    sandeep43 is offline Member
    Join Date
    May 2011
    Posts
    97
    Rep Power
    0

    Default

    Hi guys,

    i am already using variable as pbrockway2 said, since i could not accomplish the task i wanted to use array concept and

    @josAh: since i was closing the loop and later also i want to use same values i think my array should be global

    So how can i do it guys, help me out?

    Regards
    Sandeep

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by sandeep43 View Post
    Hi guys,
    @josAh: since i was closing the loop and later also i want to use same values i think my array should be global

    So how can i do it guys, help me out?
    I think you're misunderstanding some of the very basic concepts of the Java language. For one thing: reading a ResultSet and storing its values in an array is tricky: you have to know the number of values in advance; another thing: you can return those values from a method and the caller of the method has to know how to handle them; there is no need for anything 'global'.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    sandeep43 is offline Member
    Join Date
    May 2011
    Posts
    97
    Rep Power
    0

    Default

    ok JOsAh

    If thats the case how else can i handle the situation.

    Regards
    Sandeep

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by sandeep43 View Post
    ok JOsAh

    If thats the case how else can i handle the situation.
    Use a List of some sort to store the values of the ResultSet and return it from the method that iterates over the ResultSet and fills the List. The caller of that method should know what to do with that List.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    Your requirements are a bit thin here.
    What are you trying to achieve?
    Where is this data going?
    How much data is it?

  9. #9
    sandeep43 is offline Member
    Join Date
    May 2011
    Posts
    97
    Rep Power
    0

    Default

    ok JosAh i will give a shot for it

    @tolls: i have a sql which will retrieve data and later this data has to be processed based on few condts and data size is unknown, we cant identify how much client has data in his database.

    Sandeep

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    If there's a lot of data you might hit a memory problem trying to get it all into objects in a List.
    Worht bearing in mind, though we are talking probably in the 10s of thousands of rows here at least.

  11. #11
    sandeep43 is offline Member
    Join Date
    May 2011
    Posts
    97
    Rep Power
    0

    Default

    Hi JosAH,

    I used a variable and solved thnks for it.

    @tolls i am able to handle 40,000 tables and more also as of now, in real time it will be less than that i am pretty dam sure about it.
    Thnks guys

    Regards
    Sandeep

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by sandeep43 View Post
    Hi JosAH,

    I used a variable and solved thnks for it.

    @tolls i am able to handle 40,000 tables and more also as of now, in real time it will be less than that i am pretty dam sure about it.
    Thnks guys
    I simply don't understand how you solved it; a variable for what? 40000 tables? But never mind; I'm glad you solved your issue ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Concept question
    By erikjd21 in forum New To Java
    Replies: 3
    Last Post: 04-10-2011, 02:14 PM
  2. Need help in thread concept
    By umapathy_sekar in forum Advanced Java
    Replies: 2
    Last Post: 11-11-2010, 06:25 AM
  3. enter key concept......
    By silversurfer2in in forum AWT / Swing
    Replies: 5
    Last Post: 06-29-2010, 11:36 AM
  4. Thread concept
    By javahelp00 in forum Threads and Synchronization
    Replies: 2
    Last Post: 03-01-2009, 05:15 PM
  5. Interface concept
    By r.srimathi in forum AWT / Swing
    Replies: 5
    Last Post: 01-28-2009, 04:25 PM

Posting Permissions

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