为何 java中sql查询的结果集不能改变? 想 请问一下 , 我用 java 连接数据库后,进行了两次查询 ,可是 结果都一样(估计是结果集没变), result=start.executeQuery("select place from onplace where number ='123456'"); place = result.getString("place"); System.out.println(place); result=start.executeQuery("select place from onplace where number ='1256'"); place = result.getString("place"); System.out.println(place);
------解决方案-------------------- .... result=start.executeQuery("select place from onplace where number ='123456'"); while(result.next()){ place = result.getString("place"); System.out.println(place); }
其次主要可能是这个statement的问题,ResultSet你不用管,因为他是指向了一个新的Set; 你换一个statement应该就没问题了。所以你的ResultSet不用关。 Statement otherStmt = conn.createStatement(); result=otherStmt.executeQuery("select place from onplace where number ='1256'"); while(result.next()){ place = result.getString("place"); System.out.println(place); }