A)
//RepeatedUpdation.java
import java.util.Scanner;
import java.sql.*;
class RepeatedUpdate {
public static void main(String[] args) {
Connection con= DriverManager.getConnection("jdbc:odbc:prince","scott","tiger");
PreparedStatement ps = con.PreparedStatement("UPDATE ACCOUNT SET BALANCE=BALANCE+? WHERE ACCNO=?");
Scanner s=new Scanner(System.in);
while(true)
{
System.out.println("Enter accno : ");
int ano=s.nextInt();
System.out.println("Enter amount : ");
Float amt=s.nextFloat();
ps.setFloat(1, amt);
ps.setInt(2, ano);
int re = ps.executeUpdate();
if(re==0)
System.out.println("update not successfull");
else
System.out.println("deposit successfully");
System.out.println("one more account ? (yes/no)");
String choice=s.next();
if(choice.equals("no"))
break;
}//infinite loop
ps.close();
con.close();
}//main
}//class
Comments
Post a Comment