c3p0和QueryRunner的结合使用,让开发更加简便
2017-03-11 20:20
591 查看
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文件
2.3:创建实体类,如User.java,源码如下,
View Code
演示效果如下所示:
初试成功,等待复试(技术试),加油!!!奋斗吧,小青年
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文件
<c3p0-config> <!-- c3p0默认配置,下面还可以配置多个数据库 --> <default-config> <property name="jdbcUrl">jdbc:mysql://localhost:3306/test </property> <property name="driverClass">com.mysql.jdbc.Driver</property> <property name="user">root</property> <property name="password">123456</property> <property name="initialPoolSize">6</property> <property name="maxPoolSize">50</property> <property name="maxIdleTime">1000</property> </default-config> </c3p0-config>
2.3:创建实体类,如User.java,源码如下,
package com.bie.test; import java.util.List; import org.junit.Test; import com.bie.dao.UserDao; import com.bie.dao.impl.UserDaoImpl; import com.bie.po.User; import com.bie.service.UserService; import com.bie.service.impl.UserServiceImpl; /** * @author BieHongLi * @version 创建时间:2017年3月11日 下午5:57:25 * */ public class QueryRunnerTest { private UserDao dao=new UserDaoImpl(); private UserService service=new UserServiceImpl(); //查询所有信息的测试 @Test public void selectUser(){ List<User> list=dao.selectUser(); for(User u:list){ System.out.println(u); } } //根绝id查询的信息 @Test public void selectUserId(){ User user=dao.selectUserId(1); System.out.println(user); } //根据条件查询信息 @Test public void select(){ User user=new User(); user.setName("张三"); List<User> list=service.select(user); for(User u:list){ System.out.println(u); } } @Test public void insertUser(){ User user=new User(); user.setName("张三"); user.setPassword("123456"); user.setEmail("1748@qq.com"); user.setPhone("11223"); boolean mark=service.insertUser(user); if(mark){ System.out.println("插入成功"); }else{ System.out.println("插入失败"); } } @Test public void update(){ User user=new User(); user.setName("李四"); user.setId(1); boolean mark=service.updateUser(user); if(mark){ System.out.println("修改成功"); }else{ System.out.println("修改失败"); } } @Test public void delete(){ boolean mark=service.deleteUser(1); if(mark){ System.out.println("用户信息删除成功"); }else{ System.out.println("用户信息删除失败"); } } }
View Code
演示效果如下所示:
初试成功,等待复试(技术试),加油!!!奋斗吧,小青年
相关文章推荐
- c3p0和QueryRunner的结合使用,让开发更加简便
- c3p0和QueryRunner的结合使用,让开发更加简便
- c3p0和QueryRunner的结合使用,让开发更加简便
- c3p0和QueryRunner的结合使用,让开发更加简便
- c3p0和QueryRunner的结合使用,让开发更加简便
- c3p0和QueryRunner的结合使用,让开发更加简便
- c3p0和QueryRunner的结合使用,让开发更加简便
- c3p0和QueryRunner的结合使用,让开发更加简便
- c3p0和QueryRunner的结合使用,让开发更加简便
- c3p0和QueryRunner的结合使用,让开发更加简便
- c3p0和QueryRunner的结合使用,让开发更加简便
- c3p0和QueryRunner的结合使用,让开发更加简便
- 使用objectdatasource结合数据绑定控件进行简单三层架构的开发
- Android开发教程:shape和selector的结合使用
- Android开发教程:shape和selector的结合使用
- android开发之Notification结合PendingIntent使用小结
- Android开发教程:shape和selector的结合使用
- 使用objectdatasource结合数据绑定控件进行简单三层架构的开发
- Android开发教程:shape和selector的结合使用
- 使用VC和MATCOM结合开发应用程序心得笔记