欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

java 微信转账_实现微信转账功能

发布时间:2025/5/22 44 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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{//根据用户输入的用户名和密码查找是否有匹配的数据

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;

}//实现查询账户余额功能

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;

}//实现转账功能

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();

}

}

}

总结

以上是生活随笔为你收集整理的java 微信转账_实现微信转账功能的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。