Transfer example (i): DAO level Implementation (this example uses Queryrunner to execute SQL statements, data source is C3P0)

Source: Internet
Author: User

Cons: The DAO level completes the service level operation, which is detrimental to later code modification and refactoring

1. Create your own C3p0util

Account Database

2.jar Pack

3.Dao level

Interface:

 PackageCom.learning.dao;ImportCom.learning.domain.Account; Public InterfaceAccountdao {/*** Transfer *@paramfromname Transfer out user *@paramtoname Transfer to User *@paramMoney transfer Amount*/     Public voidUpdateaccount (String fromname,string ToName,DoubleMoneythrowsException;}

Implementation class:

 PackageCom.learning.dao.impl;Importjava.sql.SQLException;ImportOrg.apache.commons.dbutils.QueryRunner;Importcom.learning. Dao. Accountdao;Importcom.learning. util. C3p0util; Public classAccountdaoimplImplementsAccountdao { Public voidUpdateaccount (String fromname, String toname,DoubleMoneythrowsException {//Create a Queryrunner objectQueryrunner QR =NewQueryrunner (C3p0util.getdatasource ()); Qr.update ("Update account set money=money-?" where Name=? ", Money,fromname); Qr.update ("Update account set money=money+?" where Name=? ", Money,toname); }}

Transfer example (i): DAO level Implementation (this example uses Queryrunner to execute SQL statements, data source is C3P0)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.