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能够真正的将数据从数据库中删除,但是好像不行,那么如果使用该函数将数据真正从数据库中删除呢?

解决方案 »

  1.   


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

  2.   

    你确定id是3?
    SQLFeatureNotSupportedException异常也catch看看,
    还有属性改为TYPE_SCROLL_SENSITIVE看看
      

  3.   

    对呀,我要删除id等于3的那条记录。我使用的是JDK 1.5,里面没有SQLFeatureNotSupportedException这个类。按照2楼的方法试了也不行。我想使用ResultSet中的deleteRow函数来删除数据库里的记录,因为在有时候SQL语句写起来很长…,当然在我的这个例子中不长……
      

  4.   

    我的意思就是
    if(id==3) 

    rs.deleteRow(); 

    这个代码执行了没?
    if(id==3) 

    rs.deleteRow();
    System.out.println("ok"); 

    看看
      

  5.   

    if(id==3)  
    {  
    rs.deleteRow();  

    这段代码已经执行了……但是就是没有删除数据库中的记录……