JDBC中ResultSet的修改
JDBC的ResultSet对象,一般用法中update和select是由独立的Statement来完成。
尝试了一下直接update结果集。数据库oracle9i,驱动classes12.jar
Connection con = ds.buildConnection();
PreparedStatement smt = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = smt.executeQuery();
while(rs.next()){
rs.updateString("name","test"); rs.updateRow();
}
分别使用不同的sql:
String sql = "select a.name,b.id from user a,user_employee b where a.id = b.user_id";
这样的做法会抛出异常,rs这个时候是只读的。
String sql = "select a.name from user a";
单表操作的时候没有问题。
String sql = "select * from user"
用*的方式有问题,rs只读。
再尝试一种方式:
String sql = "select id id1 mycol,name from user";
修改一下update语句:
rs.updateInt("aa",1);
这个时候,rs仍然保持是updatable,但是这句话却会引起一个异常:
java.sql.SQLException: ORA-01733: 此处不允许虚拟列
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
。。。。。。
当然这一列通过dbmeta来获取也是readonly的。
总结一下,基本上,是单表的,非虚列,非通配符的statement可以被修改,而其他则不行。
只在jdk文档中找到了一段话是和ResultSet相关的:
A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, you can iterate through it only once and only from the first row to the last row. It is possible to produce ResultSet objects that are scrollable and/or updatable. The following code fragment, in which con is a valid Connection object, illustrates how to make a result set that is scrollable and insensitive to updates by others, and that is updatable. See ResultSet fields for other options.
- 最新文章
- JTable中怎样获取鼠标所在位置的行数[05-16]
- JSP 读取HTTP请求头[05-16]
- JSP 设置HTTP应答头[05-16]
- JSP 处理Cookie[05-16]
- JSP 脚本元素、指令和预定义变量[05-16]
- 第一次感受DI[05-16]
- 相关文章
