2020年11月21日

DBUtil工具类

摘要: 1. 添加jar包 2. 获取数据源对象; DataSource ds = DataSourceUtil.getDataSource();//自己写的工具类 3. 获取QueryRunner对象 QueryRunner qr = new QueryRunner(ds); 修改:runner.upda 阅读全文

posted @ 2020-11-21 21:30 Difcipo 阅读(96) 评论(0) 推荐(0) 编辑

mysql

摘要: 1.常用数据类型 int,char,varchar,double,float,text 2. group by和order by 分组后的字段要么是分组字段或聚合函数 where和having区别: where:在分组之前进行限定;后面不能跟聚合函数的判断 having:在分组之后进行限定,如果不满 阅读全文

posted @ 2020-11-21 19:33 Difcipo 阅读(82) 评论(0) 推荐(0) 编辑

mysql聚合函数

摘要: 1.count() ;计算个数 聚合函数计算和会排出null select count(english) from user; 聚合函数会排出null. 解决办法: 1. select count(ifnull(english,0)) from user; 2. 选择不包含空的列计算(一般会选择主键 阅读全文

posted @ 2020-11-21 19:20 Difcipo 阅读(76) 评论(0) 推荐(0) 编辑

JdbcTemplate

摘要: 1.导入jar包 2.创建JdbcTemplate对象,依赖于数据源DataSource JdbcTemplate jt = new JdbcTemplate(new ComboPooledDataSource()); //依赖于数据源DataSource 3.调用JdbcTemplate方法来完成 阅读全文

posted @ 2020-11-21 18:59 Difcipo 阅读(76) 评论(0) 推荐(0) 编辑

抽取jdbc工具类JdbcUtil

摘要: 1.在src下创建一个jdbc.properties文件 url=jdbc:mysql:///demo user=root password=123 driver=com.mysql.jdbc.Driver 2.编写工具类 public class JdbcUtil { private static 阅读全文

posted @ 2020-11-21 11:27 Difcipo 阅读(124) 评论(0) 推荐(0) 编辑

使用c3p0链接数据库

摘要: 1.导入jar包c3p0-0.9.1.2.jar , mchange-commons-java-0.2.19.jar 2.定义配置文件 名称:c3p0-config.xml <?xml version="1.0" encoding="UTF-8"?> <c3p0-config> <default-c 阅读全文

posted @ 2020-11-21 10:56 Difcipo 阅读(114) 评论(0) 推荐(0) 编辑

使用jdbc连接数据库

摘要: 1.导入jar包 mysql-connector-java-5.1.7-bin.jar。并加入到环境中。 2.注册驱动,获取连接 //注册驱动 Class.forName("com.mysql.jdbc.Driver");//com.mysql.jdbc.Driver mysql驱动 //获取链接 阅读全文

posted @ 2020-11-21 10:26 Difcipo 阅读(64) 评论(0) 推荐(0) 编辑

导航