当前位置: 技术问答>java相关
有关可更新结果集的问题
来源: 互联网 发布时间:2017-04-25
本文导语: 以下是我的一段试验程序,虽然设置结果集为可更新,但是实际运行时,系统却报错说结果集是只读的。请各位帮忙! import java.sql.*; import oracle.jdbc.OracleDriver; /** * @author Zhangjie * * To change this generated comment...
以下是我的一段试验程序,虽然设置结果集为可更新,但是实际运行时,系统却报错说结果集是只读的。请各位帮忙!
import java.sql.*;
import oracle.jdbc.OracleDriver;
/**
* @author Zhangjie
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class AdvResultSetExample2 {
/**
* Constructor for AdvResultSetExample.
*/
public AdvResultSetExample2() {
super();
}
public static void main(String[] args) throws SQLException {
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
Connection conn =
DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:jmas",
"user",
"user");
conn.setAutoCommit(false);
Statement stmt =
conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("select * from customers");
rs.absolute(2);
System.out.println("first_name = "+ rs.getString("first_name"));
System.out.println("dob = "+ rs.getString("dob"));
String newFirstName = "yu";
rs.updateString("first_name",newFirstName);
import java.sql.*;
import oracle.jdbc.OracleDriver;
/**
* @author Zhangjie
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class AdvResultSetExample2 {
/**
* Constructor for AdvResultSetExample.
*/
public AdvResultSetExample2() {
super();
}
public static void main(String[] args) throws SQLException {
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
Connection conn =
DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:jmas",
"user",
"user");
conn.setAutoCommit(false);
Statement stmt =
conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("select * from customers");
rs.absolute(2);
System.out.println("first_name = "+ rs.getString("first_name"));
System.out.println("dob = "+ rs.getString("dob"));
String newFirstName = "yu";
rs.updateString("first_name",newFirstName);
|
在rs.updateString("first_name",newFirstName);
加上rs.updateRow()
加上rs.updateRow()