Db2 JDBC——当我更新1个用户余额时,尝试创建一个ATM应用程序所有用户余额都已更新

Db2 JDBC——当我更新1个用户余额时,尝试创建一个ATM应用程序所有用户余额都已更新,db2,Db2,我正在尝试使用JDBC和DB2编写一个程序,用户可以在其中存款或取款。但我为一个用户存款所有用户余额正在更新。我应该怎么做才能只更新一个用户余额 语句stmt=conn.createStatement() 您需要在对账单上添加where子句,以便只更新选定的客户余额,例如where id=1 ResultSet rs=stmt.executeQuery("select * from customers"); while(rs.next()) { String e

我正在尝试使用JDBC和DB2编写一个程序,用户可以在其中存款或取款。但我为一个用户存款所有用户余额正在更新。我应该怎么做才能只更新一个用户余额

语句stmt=conn.createStatement()


您需要在对账单上添加where子句,以便只更新选定的客户余额,例如where id=1

   ResultSet rs=stmt.executeQuery("select * from customers");


 while(rs.next())
   {
        String ename= rs.getString("cos_name");
        String id = rs.getString("cos_pws");

        if(ename.equalsIgnoreCase(uname) && id.equalsIgnoreCase(upass))
        {
            System.out.println("enter 1 deposit");
            System.out.println("enter 2 withdraw");
            System.out.println("enter 3 balance");
            System.out.println("enter 4 for exit");

            int input=scan.nextInt();
            switch(input)
                {

                        case 1: System.out.println("enter deposit amount");
                        double deposit=scan.nextFloat();

                        Double bal=rs.getDouble("cos_balance");
                        if(deposit>0)
                        {
                            bal=bal+deposit;
                            String st2="update customers set cos_balance="+bal;
                            stmt.executeUpdate(st2);


                            System.out.println(bal);
                        }
                        break;