Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Returning different objects from a result set  RSS feed

 
Stephen Murray
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am doing an application which requires me to return an Integer and Long value obtained from a result set in a method. As these are different types and cannot be used in an array can someone please advise me on how to access these values in the calling method, thanks.
 
Paul Clapham
Sheriff
Posts: 22203
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who says they can't be in an array? They are both subclasses of Object, after all.

But it's usually better to create a class to represent a row of a ResultSet. In your case the class would have two attributes which are int and long values.
 
Stephen Murray
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Who says they can't be in an array? They are both subclasses of Object, after all.

But it's usually better to create a class to represent a row of a ResultSet. In your case the class would have two attributes which are int and long values.


What type of arrays can store more than one type? I have been looking (a lot) and did not come across one.
 
Paul Clapham
Sheriff
Posts: 22203
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object arrays can store any type of object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!