net.ucanaccess.jdbc.UcanaccessSQLException: attemp

2020-05-05 18:25发布

问题:

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


标签: java hsqldb jdb