gpt4 book ai didi

java - deleterow() 仅适用于可更新的结果集

转载 作者:行者123 更新时间:2023-12-01 20:00:00 25 4
gpt4 key购买 nike

我将我的语句声明为 result.concur_update ,但是如果我尝试使用 deleterow() ,则会显示 deleterow() 错误仅适用于 resultset.concur_updatable

 public static void main(String args[]) throws 
ClassNotFoundException,SQLException
{
String driver="oracle.jdbc.OracleDriver";
String url="jdbc:oracle:thin:@localhost:1521:XE";
String user="system"; String pass="sysdb";
Class.forName(driver);
Connection con=DriverManager.getConnection(url,user,pass);
Statement st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String query="SELECT * FROM employees";
ResultSet rs=st.executeQuery(query);
System.out.println("S.No\tid\tname");
while(rs.next())
{
System.out.print(rs.getRow()+"\t");
System.out.print(rs.getString(1)+"\t");
System.out.println(rs.getString("emp_name"));
}
rs.absolute(3);

rs.deleteRow();
}

}

最佳答案

Oracle 数据库 JDBC 开发人员指南中记录的,结果集一章,Resultset Limitations and Downgrade Rules 部分:

To produce an updatable result set:

[..]

  • A query cannot use SELECT * .
    However, there is a workaround for this.

[..]

As a workaround for the SELECT * limitation, you can use table aliases, as shown in the following example:

SELECT t.* FROM TABLE t ...

您当前的查询不满足这些要求(也不满足 TYPE_SCROLL_SENSITIVE 的要求),因此它被降级为不可更新、滚动不敏感的结果集。

换句话说,您需要将查询更改为 SELECT e.* FROMEmployees e 或显式列出列。我建议您阅读该部分的其余部分,因为它提供了重要信息。

关于java - deleterow() 仅适用于可更新的结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48342208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com