原因:
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在出错情况外不执行即可。
本文探讨了在使用MyBatis时遇到的Nodatafound异常问题,特别是当尝试多次读取ResultSet中某列的值时。文章详细解释了问题产生的原因,并提供了一种简单有效的解决方案——通过配置log4j来禁用ResultSetLogger的日志记录。

被折叠的 条评论
为什么被折叠?



