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

情到浓时终转凉″ 提交于 2019-12-02 20:02:55

问题


           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: attempt to assign to non-updatable column


回答1:


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.

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


来源:https://stackoverflow.com/questions/28518989/net-ucanaccess-jdbc-ucanaccesssqlexception-attempt-to-assign-to-non-updatable-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!