我将TableModel用来封装JDBC里面的ResultSet,传入ResultSet后,将生成的Model对象用于Table,这样使Table显示MySQL传回来的查找结果。我的SQL语句是
select Number, Band_Name, Model, OS, Price,  Available from tb_phone where ......
查找的条件的列名只是表的一部分,现在Table显示一切正常,但是如果双击Table数据进行修改,那么会抛出异常,如下:
SEVERE: null
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, can not use functions and must select all primary keys from that table.
我在TableModel里面重写的setVlueAt()方法如下:public void setValueAt(Object aValue, int row, int colum) {
        try {
            //结果集定位到对应的行数
            rs.absolute(row + 1);
            //修改单元格对应的值
            rs.updateObject(row + 1, aValue);
            //提交修改
            rs.updateRow();
            //触发单元格的修改时间
            fireTableCellUpdated(row, colum);
        } catch (SQLException ex) {
            Logger.getLogger(ResultSetTableModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }所以不知道该怎么做?
现在MySQL里面的表有主键,就是Number。其他的约束条件则都是非空

解决方案 »

  1.   

    你的statement必须如下定义:
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); 
      

  2.   

    你的statement必须如下定义:
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
      

  3.   


    记得貌似TableModel需要调用:JTable jtable=new JTable();
    hideColumn(jtable, 0);
    public static void hideColumn(JTable table, int index) {
            TableColumn tc = table.getColumnModel().getColumn(index);
            tc.setMaxWidth(0);
            tc.setPreferredWidth(0);
            tc.setWidth(0);
            tc.setMinWidth(0);
    }