• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to return multivalue in java  RSS feed

 
albert sie
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm code something in java bean. my problem is how i can return multivalue in the method coz i want to retrieve data in database and return to jsp
my method is to use function to return multivalue


but after i compile the "int cannot be dereferenced" error message come out. i know that the int cannot use "add". can anyone suggest any better method to return multivalue??

thank you

regards,
albert
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16048
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with your code is that you have some private member variables (seqNo, desc, um, ...), and you also have some local variables inside the method materialOnSite with the same names.

The local variables hide the member variables. So if you use for example seqNo inside the method, you are referring to the local variable, which is an int, and not the member variable (which is a Vector).

You don't seem to need the local variables at all. Just remove the declarations from your code.
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
two more issues about better oo-design:

- program against an interface, not an implementation. this makes your code more decoupled, and thereby easier to understand, maintain and refactor.



- don't use old-fashioined vetors if you don't need the synchronized overhead. arraylists are usually way better.



:-)

jan
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to return multiple values is to return a holder of some sort with multiple values inside it. In this case you're returning multiple rows each of which has multiple columns, so you can do this trick twice.

First, make a little class that represents one row. It just needs a field per column. Create a new instance of this class per row. Then make a collection of rows, perhaps some sort of List or Set. Look into the available Collecitons and see which looks like a good fit.

Does this sound like an interesting way to go?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!