public void Deposite() throws Exception
{
try
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/bank";
Connection con = DriverManager.getConnection(url,"root","admin");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter your A/c no. : ");
acNo = Integer.parseInt(br.readLine());
String sql = "SELECT Name,Ac_No,Balance FROM CUSTOMER WHERE Ac_No=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1,acNo);
ResultSet rs = ps.executeQuery();
while(rs.next())
{
String name = rs.getString("Name");
int acNo = rs.getInt("Ac_No");
float bal = rs.getFloat("Balance");
System.out.println(" "+name+" "+acNo+" "+bal);
}
System.out.println("Current Bal : "+bal);
BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Deposite Amt : ");
amt = Float.parseFloat(br1.readLine());
bal = bal + amt;
//System.out.println("Current Bal : "+bal);
String sql1 = "UPDATE CUSTOMER SET Balance = ? WHERE Ac_No =?";
ps = con.prepareStatement(sql1);
ps.setInt(1,acNo);
ps.setFloat(2,bal);
int i = ps.executeUpdate();
System.out.println("New Balance updated.... "+i);
System.out.println("Transaction Successful....");
ps.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
sir..i我沒有得到平衡後while循環......當我嘗試了最新它...它顯示零值在控制檯的平衡......而它仍然包含創建過程中的值就是我插在第一/ C ... PLZ HLP我...... console output
你在循環中有一個局部變量'bal',並且可能還有一個本地字段'bal'。也用於UPDATE:'ps.setInt(2,acNo);'等等。 –
所以...我應該在鱈魚eto中做出什麼樣的修正才能得到正確的o/p //// –
但我在程序中聲明瞭「bal」作爲類變量......並且我正在訪問它...所以我認爲它可能在埃夫裏點作爲課堂級別變量工作... –