How can I have a Java method return multiple values?

前端 未结 6 2014
灰色年华
灰色年华 2020-12-21 19:10

I was just wondering whether there\'s a way to make a Java method return multiple values.

I\'m creating an application that uses the jdbc library to work with a data

6条回答
  •  醉酒成梦
    2020-12-21 19:32

    You can't exactly return multiple values from a method in Java, but you can always return a container object that holds several values. In your case, the easiest thing to do would be to return the ResultSet, Customer.

    If you're concerned about exposing your data layer to your UI, you can copy the data from the ResultSet into a structure that is less specific to the database, either a List of Maps, or perhaps a List of Customer objects, where Custom is a new class that represents your business entity.

提交回复
热议问题