日期:2014-05-20  浏览次数:20880 次

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

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