【java.sql.SQLException: Before start of result set】
将ResultSet转换为 Map<String,String>时抛出了一个这样的异常:java.sql.SQLException: Before start of result set
网上查了下,说是必须这么写:
1 while (rs.next()){ 2 3 ... ... 4 }
具体为什么必须这么写呢?stackoverflow上面的阿三大兄弟给出了答案:
Would it be safe to use result.next() or result.first() when executing a simple COUNT query because it should never be null and will only ever be 1 result.
翻译:使用 result.next() or result.first() 为了保证安全,因为它永远不应该为null并且结果只会是1;
原文地址:https://stackoverflow.com/questions/2120255/resultset-exception-before-start-of-result-set
吐槽:浓浓的咖喱味英语 呕~~~