1. to update a column value in the current row. In a scrollable ResultSet object, the cursor can be moved backwards and forwards, to an absolute position, or to a position relative to the current row. The following code fragment updates the NAME column in the fifth row of the
ResultSet object rs and then uses the method updateRow to update the data source table from which rs was derived. rs.absolute(5); // moves the cursor to the fifth row of rs
rs.updateString("NAME", "AINSWORTH"); // updates the
// NAME column of row 5 to be AINSWORTH
rs.updateRow(); // updates the row in the data source
2. to insert column values into the insert row. An updatable ResultSet object has a special row associated with it that serves as a staging area for building a row to be inserted. The following code fragment moves the cursor to the insert row, builds a three-column row, and inserts it into rs and into the data source table using the method insertRow. rs.moveToInsertRow(); // moves cursor to the insert row
rs.updateString(1, "AINSWORTH"); // updates the
// first column of the insert row to be AINSWORTH
rs.updateInt(2,35); // updates the second column to be 35
rs.updateBoolean(3, true); // updates the third row to true
rs.insertRow();
rs.moveToCurrentRow();
ResultSet object rs and then uses the method updateRow to update the data source table from which rs was derived. rs.absolute(5); // moves the cursor to the fifth row of rs
rs.updateString("NAME", "AINSWORTH"); // updates the
// NAME column of row 5 to be AINSWORTH
rs.updateRow(); // updates the row in the data source
2. to insert column values into the insert row. An updatable ResultSet object has a special row associated with it that serves as a staging area for building a row to be inserted. The following code fragment moves the cursor to the insert row, builds a three-column row, and inserts it into rs and into the data source table using the method insertRow. rs.moveToInsertRow(); // moves cursor to the insert row
rs.updateString(1, "AINSWORTH"); // updates the
// first column of the insert row to be AINSWORTH
rs.updateInt(2,35); // updates the second column to be 35
rs.updateBoolean(3, true); // updates the third row to true
rs.insertRow();
rs.moveToCurrentRow();
解决方案 »
- java数据库设计中的14个技巧
- 使用org.apache.commons.net.ftp.FTPClient storeFile(String,ImputStream) 被锁的问题
- 空字符 == null吗?
- java中怎么获取choice中的字符串
- 什么是数据库驱动程序
- 参数传递(在线等)
- 类型转化问题
- 为何java程序里繁体字显示为方块,GB2312的没问题,怎么同时
- 我自己在寫一個Application Server,各位可否幫忙?
- 大家好!我是java的初学者,有了一定的编程基础,能帮我找本好书吗??谢谢!!
- 用ResultSet的updateRow方法操作记录出现的 问题 ?
- sunjiujiu,可以认识一下吗?
con = DriverManager.getConnection(url,"sa", "sa");
stmt = con.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery("select payment from employee");
//从员工表里选出工资字段
rs.absolute(1); //定位到第一条纪录
rs.updateInt(1,25);//更改第一个字段的值
rs.updateRow();//执行更新操作
结果出错:odbc驱动程序:无效的属性/选项标识符
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);////here,look at here!
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
// rs will be scrollable, will not show changes made by others,
// and will be updatable