deleteRow的使用问题

htty326 2008-04-22 08:59:51
import java.sql.*;

public class ProData {
public static void main(String args[]) {
Connection con;
PreparedStatement stmt;
ResultSet rs;
String sql = "select * from data order by id";
long id = 0;
//double data;
try {
System.out.println("OK");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:RTree");
stmt = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery();
System.out.println(rs.getConcurrency());
while(rs.next())
{
id=rs.getLong("id");
if(id==3)
{
rs.deleteRow();
}
}
System.out.println("Finish!");

} catch (SQLException e) {
System.out.println(e.getMessage());
System.out.println(e.getSQLState());
System.out.println(e.getErrorCode());
} catch (Exception e) {

}

}

}
如何将删除的结果更新到数据库中呢?文档里说deleteRow能够真正的将数据从数据库中删除,但是好像不行,那么如果使用该函数将数据真正从数据库中删除呢?
...全文
283 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
htty326 2008-05-06
  • 打赏
  • 举报
回复
if(id==3)
{
rs.deleteRow();
}
这段代码已经执行了……但是就是没有删除数据库中的记录……
anqini 2008-04-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 htty326 的回复:]
对呀,我要删除id等于3的那条记录。我使用的是JDK 1.5,里面没有SQLFeatureNotSupportedException这个类。按照2楼的方法试了也不行。我想使用ResultSet中的deleteRow函数来删除数据库里的记录,因为在有时候SQL语句写起来很长…,当然在我的这个例子中不长……
[/Quote]
我的意思就是
if(id==3)
{
rs.deleteRow();
}
这个代码执行了没?
if(id==3)
{
rs.deleteRow();
System.out.println("ok");
}
看看

htty326 2008-04-24
  • 打赏
  • 举报
回复
对呀,我要删除id等于3的那条记录。我使用的是JDK 1.5,里面没有SQLFeatureNotSupportedException这个类。按照2楼的方法试了也不行。我想使用ResultSet中的deleteRow函数来删除数据库里的记录,因为在有时候SQL语句写起来很长…,当然在我的这个例子中不长……
anqini 2008-04-23
  • 打赏
  • 举报
回复
你确定id是3?
SQLFeatureNotSupportedException异常也catch看看,
还有属性改为TYPE_SCROLL_SENSITIVE看看
Shine_Panda 2008-04-22
  • 打赏
  • 举报
回复

再创建一个语句对象执行 "delete from data where id=3"

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧