Transfer example (1): Dao implementation (in this example, QueryRunner is used to execute SQL statements, and the data source is C3P0 ),

Source: Internet
Author: User

Transfer example (1): Dao implementation (in this example, QueryRunner is used to execute SQL statements, and the data source is C3P0 ),

Disadvantage: the Dao layer completes Service-level operations, which is not conducive to later code modification and reconstruction.

1. Create C3P0Util on your own

Account Database

 

2. jar package

3. Dao Layer

Interface:

Package com. learning. dao; import com. learning. domain. account; public interface AccountDao {/*** transfer * @ param fromname transfer user * @ param toname transfer user * @ param money transfer amount */public void updateAccount (String fromname, string toname, double money) throws Exception ;}

Implementation class:

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 {// create a QueryRunner object QueryRunner qr = new QueryRunner (C3P0Util. getDataSource (); qr. u Pdate ("update account set money = money -? Where name =? ", Money, fromname); qr. update (" update account set money = money +? Where name =? ", Money, toname );}}

 

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.