博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
转账示例(一):Dao层面实现(本例采用QueryRunner来执行sql语句,数据源为C3P0)...
阅读量:4605 次
发布时间:2019-06-09

本文共 1006 字,大约阅读时间需要 3 分钟。

缺点:Dao层面把Service层面的操作完成了,不利于后期的代码修改和重构

1.自行创建C3P0Util

account数据库

 

2.jar包

3.Dao层面

接口:

package com.learning.dao;import com.learning.domain.Account;public interface AccountDao {    /**     * 转账     * @param fromname 转出用户     * @param toname  转入用户     * @param money  转账金额     */    public void updateAccount(String fromname,String toname,double money)throws Exception;}

 实现类:

package com.learning.dao.impl;import java.sql.SQLException;import org.apache.commons.dbutils.QueryRunner;import com.learning.dao.AccountDao;import com.learning.util.C3P0Util;public class AccountDaoImpl implements AccountDao {    public void updateAccount(String fromname, String toname, double money) throws Exception {        //创建一个QueryRunner对象        QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());        qr.update("update account set money=money-? where name=?",money,fromname);        qr.update("update account set money=money+? where name=?",money,toname);    }}

 

转载于:https://www.cnblogs.com/youwillsee/p/6664836.html

你可能感兴趣的文章
Bogart BogartAutoCode.vb
查看>>
hdu - 2266 How Many Equations Can You Find (简单dfs)
查看>>
UIView属性
查看>>
将博客搬至CSDN
查看>>
远程服务器git搭建
查看>>
牛人们的博客地址
查看>>
Zabbix是什么?
查看>>
源码:COCO微博
查看>>
面向对象预习随笔
查看>>
大数据概念炒作周期模型
查看>>
排序模型
查看>>
Dede推荐文章与热点文章不显示?
查看>>
React 3
查看>>
Topshelf 使用
查看>>
Linux --Apache服务搭建
查看>>
20145325张梓靖 实验三 "敏捷开发与XP实践"
查看>>
JavaScript面试题
查看>>
[转帖]架构师眼中的高并发架构
查看>>
ios的一些开源资源
查看>>
HTTP 错误 500.21 - Internal Server Error 解决方案
查看>>