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: 更新不可能な列に割り当てようとしています