轉賬樣本(一):Dao層面實現(本例採用QueryRunner來執行sql語句,資料來源為C3P0),

來源:互聯網
上載者:User

轉賬樣本(一):Dao層面實現(本例採用QueryRunner來執行sql語句,資料來源為C3P0),

缺點: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);    }}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.