当提到存储过程时客户端得到两个Resultset。第一个一切都很好,但第二个包含 20 行,客户端开发人员声称该过程返回大约 1000。
Connect connectObject = new Connect();
Connection connectionToPool = null;
CallableStatement procedure = null;
ResultSet table = null;
int rowCounter;
SOATO answer = new SOATO();
int counter = 1;
try {
connectObject.init(POOL);
connectionToPool = connectObject.getConnection();
procedure = connectionToPool.prepareCall("{call procedure()}");
procedure.execute();
while (true) {
rowCounter = procedure.getUpdateCount();
if (rowCounter > 0) { // This is update counter
procedure.getMoreResults();
continue;
}
if (rowCounter == 0) { // DDL command or 0 updates
procedure.getMoreResults();
continue;
}
table = procedure.getResultSet(); // If we reached here, we have a
// set of data, or no more results
if (table != null) {
switch (counter) {
case 1: // Area tables
answer.areaDataHandler(table);
counter++;
break;
case 2: // Region tables
answer.regionDataHandler(table);
counter++;
break;
default:
break;
}
procedure.getMoreResults();
continue;
}
break; // No more results
}
} catch (SQLException e) {
e.toString();
} finally {
if (table != null) {
try {
table.close();
} catch (SQLException e) {
e.toString();
}
}
if (procedure != null) {
try {
procedure.close();
} catch (SQLException e) {
e.toString();
}
}
if (connectionToPool != null) {
connectObject.releaseConnection(connectionToPool);
}
}
return answer;
}
regionDataHandler() 类似 areaDataHandler()
public void areaDataHandler(ResultSet table) throws SQLException {
while (table.next()) {
Area temp = new Area();
temp.setKodobl(table.getInt("kodobl"));
temp.setNameobl(table.getString("nameobl"));
area.add(temp);
}
}
- 数据库 - MSSQL 2000
- jdbc驱动-jtds1.2.5
ps请不要严格判断初级和英语不好的对不起