美好的一天,我搜索了几个关于如何将结果集中的值保存在变量中的问题。由于我使用的是函数,因此我不知道要在 ResultSetVar.getString("") 函数中放入什么内容。
这是我的查询。
sqlSelectRecord1 = "SELECT COUNT(name) as acount from maintable where VLdate = ?";
psSelectRecord1=conn.prepareStatement(sqlSelectRecord1);
psSelectRecord1.setString(1, strDateofVL);
rsSelectRecord1=psSelectRecord1.executeQuery();
String strCount;
Integer iCount;
while (rsSelectRecord1.next()) {
strCount = rsSelectRecord1.getString(acount);
iCount = Integer.valueOf(strCount);
}
我遇到错误,提示无法将 acount 解析为变量。我猜它不会在我的查询中读取我的 AS 帐户。我该如何度过这个难关?
最佳答案
您必须使用名称。
strCount = rsSelectRecord1.getString("acount");
关于java - 如何将结果集保存到变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29644977/