net.ucanaccess.jdbc.UcanaccessSQLException: 尝试分配给不可更新的列

net.ucanaccess.jdbc.UcanaccessSQLException: attempt to assign to non-updatable column

           try{

            //taking input from user about how much balance
            Scanner input = new Scanner(System.in);
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            String url = "jdbc:ucanaccess://c://Bibek//Atmcard.accdb";
            System.out.print("\nConnecting to database...");
            con = DriverManager.getConnection(url);
            st = con.createStatement();
            System.out.println("\n Enter balance you want to withdraw:\n");


            balance = Double.parseDouble(input.nextLine());
            String sql = "select AccountBalance From Atm";
            result = st.executeQuery(sql);
                while(result.next()){
                    //assigning balanceFromDb to deduct and update in database
                    Double balanceFromDb = result.getDouble("AccountBalance");
                    balanceFromDb=balanceFromDb-balance;
                    result.updateDouble("AccountBalance", balanceFromDb);
                    result.updateRow();
                }



    }catch(Exception ex){
            System.err.println(ex.toString());
    }

输出:正在连接到数据库... 输入您要提取的余额:

20

net.ucanaccess.jdbc.UcanaccessSQLException: 尝试分配给不可更新的列

检查访问数据库中的 Atm 对象并确保它是 table 而不是查询。还要检查 AccountBalance 的数据类型并确保它是一个 editable 字段。如果它是自动递增或计算的,您将无法更新它。

编辑:看来您必须将其声明为可更新游标。这是来自 source forge http://ucanaccess.sourceforge.net/site.html 上的 ucanacces 的示例 使用 updatable 结果集

PreparedStatement ps =     super.ucanaccess.prepareStatement( "SELECT *  FROM T1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT);
rs = ps.executeQuery();
rs.next(); 
rs.updateString(2, "show must go off"); 
rs.updateRow();