• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to convert to statements to an array

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how would i convert this to an array...

 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't expect you mean to ask how to turn that code into an array:




So what, exactly is it that you want to convert to an array?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess that what you want is retrieve multiple records from the database, and store the results in an array.

An array is not the best suited collection to do this, because arrays in Java have a fixed size, which is set at the moment you create an array, and here you don't know in advance how many records you are going to retrieve from the database.

So instead of an array, it would be better to use a collection class such as ArrayList, which can grow dynamically. To put the results of the query in an ArrayList of User objects, you could do something like this:

You can learn more about collection classes such as ArrayList in the Collections Tutorial.
 
Bob Dunn
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestion, I think the arraylist is a better way to go.

so this is what I came up with but am getting an error on the statement, users.add(Selectuser); It can't find the symbol 'selectUser' but it is there. What am I doing wrong?

 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bob Dunn wrote:It can't find the symbol 'selectUser' but it is there. What am I doing wrong?


Actually the error message mentions the symbol 'Selectuser' rather than the symbol 'selectUser'. Those are two different things -- case counts in Java programming.

But anyway you say the symbol is "there". What exactly did you mean by "there"? Could you perhaps point to a line number in your post where you believe you have declared that symbol?
 
Bob Dunn
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought it is on line 39 but it obviouslyis not or else I wouldn't be getting the error. I'm just trying to add the entries to the arraylist.
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic