原因:
This typically occurs when you try to read the value of a column multiple times. For example, this may throw "No data found":
ResultSet rs = statement.executeQuery(sql);
while (rs.next()) {
if ("value1".equals(rs.getString("mycolumn")) || "value2".equals(rs.getString("mycolumn"))
只有jdbc-odbc桥接会有只能取一次值的这个问题,其他Jdbc驱动无。
private void printColumnValues(int columnCount) throws SQLException {
StringBuilder row = new StringBuilder();
row.append("<== Row: ");
for (int i = 1; i <= columnCount; i++) {
String colname;
try {
colname = rs.getString(i);
..........
也就是在正式从rs.getString取值前,ResultSetLogger已经调用过一次,所以会报No data found Java exception
解决方法:
log4j.properties 添加一行 log4j.logger.java.sql.ResultSet=ERROR
让ResultSetLogger在出错情况外不执行即可。