Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 _____ *_*__一個關于rs.next()的問題﹗
pyzl





发贴: 25
积分: 0
于 2006-08-31 10:39 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
<%
int ids=java.lang.Integer.parseInt(request.getParameter("id"));
//得到編號
String sql="select * from pur_buyer where id="+ids+"";
try{
Context initCtx=new InitialContext();
Context ctx=(Context)initCtx.lookup("java:comp/env");
//獲取連接池對象
Object obj=(Object) ctx.lookup("jdbc/sqlserver");
//類型轉換
javax.sql.DataSource ds=(javax.sql.DataSource)obj;
Connection conn=ds.getConnection();

//通過數據池連接數據庫

Statement stat=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//

ResultSet rs=stat.executeQuery(sql);

rs.next();
rs.deleteRow();
out.print("刪除成功了!!!");
}catch(SQLException e){
out.print("sql異常");
}

%>

rs.next()應該是記錄下移一條﹐但是在這我已經通過String sql="select * from pur_buyer where id="+ids+"";找到要刪除的記錄﹐如果再下移﹐那不就是刪除下一條記錄

我試了一下﹐它刪除的是查詢到的記錄﹐是正確的
后來我又把rs.next()刪除﹐測試了一下﹐結果也是正確的

到底加不加rs.next()有什么區別呢﹖﹖﹖

現在有點蒙了﹐不知道咋回事﹐忘高手指正﹗



作者 Re:_____ *_*__一個關于rs.next()的問題﹗ [Re:pyzl]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-08-31 18:57 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Please consider not putting something like ____ *_*__ in the subject.

Initially the cursor is positioned before the first row. You need rs.next() to move it to the first row.

Which DB (JDBC) are you using?
The API doc writes ResultSet's deleteRow "throws SQLException if a database access error occurs or if this method is called when the cursor is on the insert row", but it doesn't mention it is a "database access error" when the cursor is not at an appropiate "position" -- the JDBC implmentation could move it to the first row, though I think is inappropiate.

How many records were returned from select * from pur_buyer where id='ids'
if there are more than 1, you may try
rs.next();
rs.next();
rs.deleteRow();
and check whether the first or second one is deleted.

I would use
rs.first();
rs.deleteRow();


why edited on 2006-08-31 19:40

作者 Re:_____ *_*__一個關于rs.next()的問題﹗ [Re:pyzl]
pyzl





发贴: 25
积分: 0
于 2006-09-01 10:39 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我用的試SQL server2000

rs.next();
rs.next();
rs.deleteRow();

這個我也試過﹐可是會出錯﹗




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923