• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

how to return multivalue in java

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
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
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.
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic