I have written a method in Java which returns 2 values. 1st Count of result which is of int type and 2nd if the method is success true/false boolean type. How can I return both values? So that if the method is a success then only proceed.
Sample code:
public static void main(String args[])
{
int count = 0;
boolean status = false;
//count = retrieveData(); Current code working but captures only 1 values at a time i.e. Count not the status
/* Expected Code
if (status == true) // where status and count is returned from retrieveData method
{
count = retrieveData();
System.out.println("Status is true so can proceed");
}
else
System.out.println("Status is not true so don't proceed");
*/
}
public static int retrieveData() throws Exception
{
boolean success = false;
String query = "SELECT Count(1) FROM Account";
int totalCount=0;
ResultSet rsRetrieve = null;
Statement stmt = null;
stmt = conn.createStatement();
rsRetrieve = stmt.executeQuery(query);
while (rsRetrieve.next())
{
totalCount= rsRetrieve.getInt(1);
System.out.println("totalCount : "+totalCount);
}
success = true;
return totalCount; // current working code but returns only 1 value i.e. Count not status
/* Expected
return success + totalCount
*/
}