想 请问一下 ,
我用 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);为何两次都输出的是同一个结果?
储存数据的时候,明明第二个number ='1256'没有值的,可是也输出的是 上面的一个结果,这是为什么?
我在中间加了 result.close();依然不行!!!我换了一下 先查 number ='1256', 结果是对的 输出的 是
null 12;
但是 我要是先查 number=‘123456’,结果却是 12 12;
这是为什么???? 高手帮忙呀!!!
我用 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);为何两次都输出的是同一个结果?
储存数据的时候,明明第二个number ='1256'没有值的,可是也输出的是 上面的一个结果,这是为什么?
我在中间加了 result.close();依然不行!!!我换了一下 先查 number ='1256', 结果是对的 输出的 是
null 12;
但是 我要是先查 number=‘123456’,结果却是 12 12;
这是为什么???? 高手帮忙呀!!!
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);
}
可是都不成功!!!还有 3楼的做法有点不好,
如果 我是要一个循环里面多次查找呢? 难道每次都要新用一个 Statement ???
有没有其他的方法呀?
我都关闭了 ,都设置为NULL 了, 再重新连接,重新搞,依然不行,结果集就是不变!!!
public User findById(int id){
//code
}
请问,public User findById 是什么意思?
不懂
请仔细看一下我的题目,
不同 123456的 place是 12
另外一个 没有记录,应该是null的,但是也输出 12;
我知道 ,我这是简写、、、
if(result.next()){
place = result.getString("place");
}
System.out.println(place);
这是原样!!!
就是结果集不变!!!!
欢迎浏览我的博客。
http://blog.csdn.net/lb85858585