2016. 9. 5. 23:39ㆍ프로그래밍/자바
public static void depositAcc(){
try {
System.out.println("계좌번호를 입력하세요 : ");
Scanner sc = new Scanner(System.in);
String accNumber = sc.nextLine();
System.out.println("입금할 금액을 입력하세요: ");
int money = sc.nextInt();
Connection con = null;
con = DriverManager.getConnection("jdbc:mysql://localhost","root","mysql");
java.sql.Statement st = null;
ResultSet rs = null;
st = con.createStatement();
rs = st.executeQuery("use dbname");
String sql;
sql="SELECT acc_money, user_no from user_info where acc_number ='" + accNumber +"'";
rs = st.executeQuery(sql);
int acc_money = 0;
int user_no = 0;
while(rs.next()){
acc_money = rs.getInt("acc_money");
user_no = rs.getInt("user_no");
}
acc_money = money + acc_money;
sql="UPDATE user_info SET acc_money= ? where user_no = ?";
String sql2;
sql2="INSERT into inout_history(acc_number, acc_in, user_no) "
+ "values(?,?,?)";
java.sql.PreparedStatement pstmt = null;
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, acc_money);
pstmt.setInt(2, user_no);
pstmt.executeUpdate();
pstmt = con.prepareStatement(sql2);
pstmt.setString(1,accNumber);
pstmt.setInt(2, money);
pstmt.setInt(3, user_no);
pstmt.executeUpdate();
con.close();
System.out.println("계좌가 성공적으로 입금 되었습니다");
} catch (SQLException e) {
System.out.println(e.getMessage());
System.out.println("시스템에 오류가 생겼습니다.");
}
}
'프로그래밍 > 자바' 카테고리의 다른 글
알고리즘(문자열반복) (0) | 2016.09.25 |
---|---|
알고리즘 연습(최소값, 최대값) (0) | 2016.09.25 |
은행계좌 Mysql 연동 (계좌 생성+조회) (0) | 2016.09.05 |
은행 계좌 예제(list 사용) 수정완료 (0) | 2016.09.01 |
indexOf 예제 (0) | 2016.08.29 |