我正在尝试使用ionic.app.scss
获取此查询SELECT mac, stop_name from behaviour where mac = ?
的受影响记录的数量。如何获取受影响的行数?
代码:
executeQuery
答案 0 :(得分:1)
这是一个读取操作,因此不会影响任何行。如果您想获得返回的行数,那么您可以执行以下操作之一
使用计数器变量并在循环while (rsBehav.next())
使用可滚动的结果集
PreparedStatement prepared = con.prepareStatement(
"SELECT mac, stop_name from behaviour where mac = ?",
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rsBehav = prepared.executeQuery();
rsBehav.afterLast();
int numRow = rsBehav.getRow();
rsBehav.beforeFirst();
这里numRow会给你返回的数字或行,
答案 1 :(得分:0)
if (behaviourExist.next()) {
PreparedStatement prepared = con
.prepareStatement("SELECT mac, stop_name from behaviour where mac = ?");
prepared.setString(1, macD);
ResultSet rsBehav = prepared.executeQuery();
ArrayList<String> stopNameList = new ArrayList<String>();
int numberOfRows = 0;
while (rsBehav.next()) {
++numberOfRows;
String stNa = rsBehav.getString("stop_name");
if (stNa.equals(nameShortestDistance)) {
stopNameList.add(stNa);
}
}
}
这里变量numberOfRows将在每次循环运行时递增,这将为您提供resultSet中的总行数。
答案 2 :(得分:0)
PreparedStatement prepared = con
.prepareStatement(
"SELECT (SELECT count(*) from where mac = ?),"
" mac, stop_name from behaviour where mac = ?");
prepared.setString(1, macD);
prepared.setString(2, macD);
ResultSet rsBehav = prepared.executeQuery();
ArrayList<String> stopNameList = new ArrayList<String>();
while (rsBehav.next()) {
int numberOfRows = rsBehav.getInt(1);
String stNa = rsBehav.getString("stop_name");
// ....