我用 Java 编写了一个返回 2 个值的方法。第一个结果计数是 int 类型,如果方法是成功 true/false 布尔类型,则为第二个。如何返回两个值?因此,如果该方法成功,则仅继续。
示例代码:
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
*/
}
泛舟湖上清波郎朗
慕尼黑的夜晚无繁华
潇潇雨雨
炎炎设计
繁花不似锦
相关分类