1:DBUtils中的QueryRunner的使用:

  1.1:QueryRunner中提供了对SQL语句操作的api;

  1.2:主要有三个方法:

    1.2.1:query():用于执行select(查询);

    1.2.2:update():用于执行insert(插入)/update(更新)/delete(删除);

    1.2.3:batch():批处理;


2:c3p0和QueryRunner的结合使用:

  2.1:首先导包,如下所示的包;

    c3p0-0.9.1.2.jar
    commons-dbutils-1.6.jar
    mysql-connector-java-5.1.12-bin.jar  

   2.2:当然导包之前你需要创建好数据库和数据表哦!~~~ 

      在src目录下面记住配置c3p0-config.xml文件

 1 <c3p0-config>
 2     
 3     <!-- c3p0默认配置,下面还可以配置多个数据库 -->
 4     <default-config>
 5         <property name="jdbcUrl">jdbc:mysql://localhost:3306/test
 6         </property>
 7         <property name="driverClass">com.mysql.jdbc.Driver</property>
 8         <property name="user">root</property>
 9         <property name="password">123456</property>
10         <property name="initialPoolSize">6</property>
11         <property name="maxPoolSize">50</property>
12         <property name="maxIdleTime">1000</property>
13     </default-config>
14 
15 </c3p0-config>

   2.3:创建实体类,如User.java,源码如下,

 1 package com.bie.po;
 2 /** 
 3 * @author BieHongLi 
 4 * @version 创建时间:2017年3月11日 下午12:55:21 
 5 * 
 6 */
 7 public class User {
 8 
 9     private int id;
10     private String name;
11     private String password;
12     private String email;
13     private String phone;
14     public int getId() {
15         return id;
16     }
17     public void setId(int id) {
18         this.id = id;
19     }
20     public String getName() {
21         return name;
22     }
23     public void setName(String name) {
24         this.name = name;
25     }
26     public String getPassword() {
27         return password;
28     }
29     public void setPassword(String password) {
30         this.password = password;
31     }
32     public String getEmail() {
33         return email;
34     }
35     public void setEmail(String email) {
36         this.email = email;
37     }
38     public String getPhone() {
39         return phone;
40     }
41     public void setPhone(String phone) {
42         this.phone = phone;
43     }
44     @Override
45     public String toString() {
46         return "User [> phone
47                 + "]";
48     }
49     
50     
51 }
View Code

相关文章:

  • 2021-09-15
  • 2021-12-20
  • 2022-03-10
  • 2021-09-29
  • 2021-06-23
  • 2022-12-23
猜你喜欢
  • 2021-06-01
  • 2021-02-02
  • 2022-12-23
  • 2021-04-09
  • 2021-10-11
  • 2022-02-17
相关资源
相似解决方案