才开始我用access做数据库。
rs.updateRow()
rs.insertRow()statement也是建立成stat=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
一切没问题。但是换了mysql做数据库  select都可以了
但是
rs.updateRow()
rs.insertRow()
就出现如下错误
com.mysql.jdbc.NotUpdatable: Result Set not updatable.This result set must come from a statement that was created with a result set type of ResultSet.CONCUR_UPDATABLE, the query must select only one table, and must select all primary keys from that table. See the JDBC 2.1 API Specification, section 5.6 for more details.但是我的
statement还是这样的
stat=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);请问为什么呢?我的mysql是5.0的
库是这个mysql-connector-java-5.0.3-bin.jar请指教

解决方案 »

  1.   

    5.6     Updates
    A result set is updatable if its concurrency type is CONCUR_UPDATABLE. Rows in an updatable result set may be updated, inserted, and deleted. The example below updates the first row of a result set. The ResultSet.updateXXX() methods are used to modify the value of an individual column in the current row, but do not update the underlying database. When the ResultSet.updateRow() method is called the database is updated. Columns may be specified by name or number. 
    rs.first();
    rs.updateString(1, "100020");
    rs.updateFloat("salary", 10000.0f);
    rs.updateRow();The updates that an application makes must be discarded by a JDBC driver if the application moves the cursor from the current row before calling updateRow(). In addition, an application can call the ResultSet.cancelRowUpdates() method to explicitly cancel the updates that have been made to a row. The cancelRowUpdates() method must be called after calling updateXXX() and before calling updateRow(), otherwise it has no effect. The following example illustrates deleting a row. The fifth row in the result set is deleted from the database. rs.absolute(5);
    rs.deleteRow();
    The example below shows how a new row may be inserted into a result set. The JDBC API defines the concept of an insert row that is associated with each result set and is used as a staging area for creating the contents of a new row before it is inserted into the result set itself. The ResultSet.moveToInsertRow() method is used to position the result set's cursor on the insert row. The ResultSet.updateXXX() and ResultSet.getXXX() methods are used to update and retrieve individual column values from the insert row. The contents of the insert row is undefined immediately after calling ResultSet.moveToInsertRow() . In other words, the value returned by calling a ResultSet.getXXX() method is undefined after moveToInsertRow() is called until the value is set by calling ResultSet.updateXXX(). Calling ResultSet.updateXXX() while on the insert row does not update the underlying database or the result set. Once all of the column values are set in the insert row, ResultSet.insertRow() is called to update the result set and the database simultaneously. If a column is not given a value by calling updateXXX() while on the insert row, or a column is missing from the result set, then that column must allow a null value. Otherwise, calling insertRow() throws an SQLException. rs.moveToInsertRow();
    rs.updateString(1, "100050");
    rs.updateFloat(2, 1000000.0f);
    rs.insertRow();
    rs.first();A result set remembers the current cursor position "in the result set" while its cursor is temporarily positioned on the insert row. To leave the insert row, any of the usual cursor positioning methods may be called, including the special method ResultSet.moveToCurrentRow() which returns the cursor to the row which was the current row before ResultSet.moveToInsertRow() was called. In the example above, ResultSet.first() is called to leave the insert row and move to the first row of the result set. 
    Due to differences in database implementations, the JDBC API does not specify an exact set of SQL queries which must yield an updatable result set for JDBC drivers that support updatability. Developers can, however, generally expect queries which meet the following criteria to produce an updatable result set: 
    The query references only a single table in the database. 
    The query does not contain any join operations. 
    The query selects the primary key of the table it references. 
    In addition, an SQL query should also satisfy the conditions listed below if inserts are to be performed. The query selects all of the non-nullable columns in the underlying table. 
    The query selects all columns that don't have a default value.
      

  2.   

    the JDBC 2.1 API Specification, section 5.6
      

  3.   

    问题还是没搞清楚
    不理解为什么同样的设置access没有任何问题
    换成mysql就会出现问题。
    我的mysql连接上了,可以操作executeUpdate
    但是rs.updateRow就不行.
    我理解的是
    如果这样stat=conn.createStatement();出现那个错误
    而stat=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    就可以了但是结果却依旧。
    继续请教
      

  4.   

    同意 java_augur(听着音乐 ☆☆☆☆☆☆)
      

  5.   

    the query must select only one table, and must select all primary keys from that table. See the JDBC 2.1 API Specification, section 5.6 for more details.1、你的查询语句必须只查询一个表,即不存在多表的关联
    2、你的查询的列,必须包含主键所有的列