Bug #48363 using Resultset.moveToInsertRow() in JDBC with mysql
Submitted: 28 Oct 2009 8:29 Modified: 28 Oct 2009 13:32
Reporter: Irfan Ali Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version: OS:Windows
Assigned to: CPU Architecture:Any

[28 Oct 2009 8:29] Irfan Ali
Description:
/////Database Description:
DROP TABLE IF EXISTS `testdb`.`mp`;
CREATE TABLE  `testdb`.`mp` (
  `name` varchar(20) default NULL,
  `kills` int(11) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

////Java Programe

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;

public class UpdateSqlTest {
public static void main(String[] args) {
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
       
       Class.forName("com.mysql.jdbc.Driver");
       conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/testdb", "root", "root");
       stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
       
       rs=stmt.executeQuery("select * from mp");//rs.setConcurrency(ResultSet.CONCUR_UPDATABLE);
       /*while (rs.next()) 
      	{
        int id = rs.getInt(2);
        String name = rs.getString(1);
        System.out.println("Name= "+name+"\t\t"+"KIILS= "+id);
        }*/
        DatabaseMetaData metadata = conn.getMetaData();
		boolean updatable = metadata.supportsResultSetConcurrency(rs.TYPE_FORWARD_ONLY, rs.CONCUR_UPDATABLE);
		System.out.println("Updatable ResultSet supported = " + updatable);
		
		 /* rs.moveToInsertRow();
          rs.updateString("name","BB");
          rs.updateInt("kills",0);
          rs.insertRow(); */
          	
        rs.close();
        stmt.close();
        conn.close();	
        	
    } catch (Exception e) 
    	{
      		System.out.println(e.getMessage());
        }
  }
}

How to repeat:
Error:
Updatable ResultSet supported = true
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.
[28 Oct 2009 13:31] Mark Matthews
Your table doesn't appear to have a primary key. The driver won't create updatable result sets for tables that don't have primary keys (there is no reliable way to determine which row to update).