Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to convert to statements to an array

 
Bob Dunn
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how would i convert this to an array...

 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15288
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic