java 微信转账_实现微信转账功能
packagecom.wx.dao;importjava.sql.Connection;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;importcom.wx.Money;importcom.wx.User;public classWxDao {//校驗用戶名和密碼
publicUser checkLogin(String user,String pwd){
PreparedStatement psmt= null;
ResultSet rs= null;
Connection con= null;
User u= null;
con=Tool.getConn2();try{//根據(jù)用戶輸入的用戶名和密碼查找是否有匹配的數(shù)據(jù)
psmt = con.prepareStatement("select * from wx_user where uname=? and pwd = ?");
psmt.setString(1, user);
psmt.setString(2, pwd);
rs=psmt.executeQuery();if(rs.next()){//將查詢的用戶名和密碼封裝到用戶對象u中
u= newUser();
u.setUid(rs.getInt(1));
u.setUname(rs.getString(2));
u.setPwd(rs.getString(3));
}
}catch(SQLException e) {
e.printStackTrace();
}finally{
Tool.close(con, psmt);
}returnu;
}//實現(xiàn)查詢賬戶余額功能
publicMoney getMoney(String user){
PreparedStatement psmt= null;
ResultSet rs= null;
Connection con= null;
Money m= newMoney();
con=Tool.getConn2();try{
psmt= con.prepareStatement("select * from wx_money where uname=? ");
psmt.setString(1, user);
rs=psmt.executeQuery();if(rs.next()){
m.setUname(rs.getString(1));
m.setMoeny(rs.getDouble(2));
}
}catch(SQLException e) {
e.printStackTrace();
}finally{
Tool.close(con, psmt);
}returnm;
}//實現(xiàn)轉(zhuǎn)賬功能
public void Transfer(doublemoney,String uname,String fname){
PreparedStatement psmt= null;
Connection con= null;
con=Tool.getConn2();try{//減去用戶賬戶中的金額
psmt = con.prepareStatement("update wx_money set money=money-? where uname=? ");
psmt.setDouble(1, money);
psmt.setString(2, uname);
psmt.executeUpdate();//增加好友賬戶中的金額
psmt = con.prepareStatement("update wx_money set money=money+? where uname=? ");
psmt.setDouble(1, money);
psmt.setString(2, fname);
psmt.executeUpdate();
}catch(SQLException e) {
e.printStackTrace();
}
}
}
總結(jié)
以上是生活随笔為你收集整理的java 微信转账_实现微信转账功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java jar log4j_java项
- 下一篇: java百度云推送demo_百度云推送j