gpt4 book ai didi

java - 使用JdbcRowSet对象更新时出现异常

转载 作者:太空宇宙 更新时间:2023-11-04 06:48:25 24 4
gpt4 key购买 nike

当我运行下面的程序时,我在更新 RowSet 时遇到异常但 scrollable 工作正常。 JdbcRowSet 默认情况下是可更新和可滚动的吗?

       java.sql.SQLException: ResultSet is not updatable
at com.sun.rowset.JdbcRowSetImpl.checkTypeConcurrency(Unknown Source)
at com.sun.rowset.JdbcRowSetImpl.updateString(Unknown Source)
at JdbcRowSet_Example.<init>(JdbcRowSet_Example.java:66)
at JdbcRowSet_Example.main(JdbcRowSet_Example.java:77)

代码片段

import com.sun.rowset.JdbcRowSetImpl;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import javax.sql.rowset.JdbcRowSet;




public class JdbcRowSet_Example {
String driver = "oracle.jdbc.driver.OracleDriver";
String url= "jdbc:oracle:thin:@192.168.1.102:1521:orcl";
String userName = "scott";
String passWord = "tiger";

public JdbcRowSet_Example() throws Exception {
Class.forName(driver);
JdbcRowSet jrs = new JdbcRowSetImpl();
jrs.setCommand("select * from Registration");
jrs.setUrl(url);
jrs.setUsername(userName);
jrs.setPassword(passWord);

jrs.execute();

ResultSetMetaData rsmd = jrs.getMetaData();
int count = rsmd.getColumnCount();
System.out.println("Number of Columns" + count);



System.out.println("Scrollable Example");

jrs.absolute(2);
for(int i=1; i<=count; i++){
System.out.print(jrs.getString(i) + "\t" + "\t"+"\t");
}
System.out.println();

System.out.println("Updatable Example");


jrs.absolute(4);


jrs.updateString(1, "Reyansh");
jrs.updateString(2,"Gogula");
jrs.updateString(3,"Rey_Gogula@hotmail.com");
jrs.updateRow();
}

/**
* @param args
*/
public static void main(String[] args) {
try {
JdbcRowSet_Example jd = new JdbcRowSet_Example();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

最佳答案

将查询更改为:从注册中选择注册。*;

我知道这看起来很愚蠢,但效果很好!

关于java - 使用JdbcRowSet对象更新时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23667818/

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