net.ucanaccess.jdbc.UcanaccessSQLException:尝试分配给不可更新的列 [英] net.ucanaccess.jdbc.UcanaccessSQLException: attempt to assign to non-updatable column

查看:187
本文介绍了net.ucanaccess.jdbc.UcanaccessSQLException:尝试分配给不可更新的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

           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());
    }

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

output: Connecting to database... Enter balance you want to withdraw:

20

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

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

推荐答案

检查Access数据库中的Atm对象,并确保它是表而不是查询.还要检查AccountBalance的数据类型,并确保它是可编辑的字段.如果它是自动递增或计算得出的,则将无法对其进行更新.

Check the Atm object in the access database and make sure it is a table and not a query. Also check the datatype for AccountBalance and make sure that it is an editable field. If it is auto incremented or calculated you will not be able to update it.

看起来您必须声明它为可更新游标.这是ucanacces上源于伪造的示例 http://ucanaccess.sourceforge.net/site.html 使用可更新的ResultSet

looks like you have to declare it an update able cursor. Here is the example from ucanacces on source forge http://ucanaccess.sourceforge.net/site.html Using updatable ResultSet

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();

这篇关于net.ucanaccess.jdbc.UcanaccessSQLException:尝试分配给不可更新的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆