MYSQL基础 数据库·····语言
DDL定义 DML操作(增删改) DQL查询 DCL控制
库与表的sql语句 CREATE创建
DROP删除
ALTER修改
对象:database数据库 table表
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 CREATE TABLE IF NOT EXISTS `student`( `id` INT (5 ) NOT NULL AUTO_INCREMENT COMMENT '学号' , `name` VARCHAR (20 ) NOT NULL DEFAULT '学生姓名' COMMENT '姓名' , `password` VARBINARY (30 ) NOT NULL DEFAULT '123456789' COMMENT '密码' , `sex` VARCHAR (5 ) NOT NULL DEFAULT '男' COMMENT '性别' , `age` INT (5 ) NOT NULL DEFAULT '18' COMMENT '年龄' , `email` VARCHAR (50 ) DEFAULT NULL COMMENT '邮箱' , PRIMARY KEY (`id`) )ENGINE= INNODB DEFAULT CHARSET= utf8 ENGINE 引擎 - INNODB 现在默认使用,安全性高。 - MYISAM 早期使用,节约空间。 CHARSET 字符集 一般选择utf8。 SHOW CREATE TABLE XXX;DESC XXX;ALTER TABLE XXX RENAME AS ··· ALTER TABLE XXX ADD ··· ALTER TABLE XXX DROP ··· ALTER TABLE XXX MODIFY ··· ALTER TABLE XXX CHANGE ···
表数据管理 insert插入 update修改 delete删除
对象一般是`表名`
注意字段用``,写常量赋值时用' '
外键 1 2 3 ALTER TABLE XXXADD CONSTRAINT `FK_xxxid` FOREIGN KEY(`xxxid`) REFERENCES `xxx`(`xxxid`);
插入 1 2 insert into `表名`(`字段名`) values ('值' );
修改 1 2 update `表名` set `字段`= '值' where 条件
删除 1 2 3 4 5 delete from `表名` where 条件truncate table `表名`
DQL查询 1 2 3 4 5 6 7 8 select ····· from ·····、 where ··· group by ··· having ··· order by ··· limit ··· union ···
DQL 1 2 3 4 5 6 7 8 9 10 11 12 13 select * from `表名` select `字段1 ` as 别名,`字段2 ` as 别名 from `表名` as 别名select concat('我的名字是 ' ,`名字字段`) as 别名 from `表名`select distinct `字段` from `表名`SELECT VERSION(); SELECT 455 * 8484 AS 结果; SELECT `studentresult`+ 1 AS 成绩加1 分 FROM `result `;
where及条件语句 简单查询 1 2 3 4 5 6 and && or || not !SELECT `studentresult` AS 成绩 FROM `result ` WHERE `studentresult`>= 80 AND `studentresult`<= 90 ;SELECT `studentresult` AS 成绩 FROM `result ` WHERE `studentresult` BETWEEN 80 AND 100 ;
模糊查询
语句
描述
a not null
若为空则真
a is not null
不为空则真
a between b and c
a在b与c之间为真
a like b
a匹配b成功则为真
a in (a1,a2,a3···)
括号内值有a则为真
1 2 3 4 select `字段` from `表名` where `字段` like '常量' select `字段` from `表名` where `字段` in ('范围' ,' ' ,' ' )
连接查询 参考网页:https://www.cnblogs.com/mafeng/p/10150013.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 SELECT s.studentno,studentname FROM student AS s INNER JOIN result AS rON s.studentno = r.studentnoselect 字段1 ,字段2 ,字段3 from 表名1 left join 表名2 on 条件SELECT s.studentno,s.studentname,subjectname FROM student AS s INNER JOIN result AS rON s.studentno = r.studentnoRIGHT JOIN `subject` AS subON r.subjectno= sub.subjectno
自连接 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 CREATE TABLE `school`.`category`( `categoryid` INT (3 ) NOT NULL COMMENT 'id' , `pid` INT (3 ) NOT NULL COMMENT '父id 没有父则为1' , `categoryname` VARCHAR (10 ) NOT NULL COMMENT '种类名字' , PRIMARY KEY (`categoryid`) ) ENGINE= INNODB COLLATE = utf8_general_ci CHARSET= utf8; INSERT INTO `category` (`categoryid`, `pid`, `categoryname`)VALUES ('2' , '1' , '信息技术' ),('3' , '1' , '软件开发' ), ('5' , '1' , '美术设计' ), ('4' , '3' , '数据库' ), ('8' , '2' , '办公信息' ), ('6' , '3' , 'web开发' ), ('7' , '5' , 'ps技术' ); SELECT a.`categoryname` AS father, b.`categoryname` AS sonFROM `category` AS a, `category` AS bWHERE a.`categoryid` = b.`pid`
排序和分页 1 2 order by 字段 asc limit a,b
子查询 1 2 3 4 5 6 7 8 9 SELECT studentno,studentname,gradeidFROM studentWHERE gradeid = ( SELECT gradeid FROM `subject` WHERE `subjectname`= '高等数学-3' )
函数
数学相关 1 2 3 4 5 6 7 8 abs () ceiling () floor () round() rand() sign() sqrt () ·····
字符串相关 1 2 3 4 5 6 7 8 char_length () length() concat() lower () upper () instr(a,b) reverse() ·····
时间日期相关 1 2 3 4 curdate() now() year () month () day () hour () minute () second ()
聚合函数 1 2 3 4 5 count () count (* ) count (1 ) count (列名) sum () avg () min () max ()
分组+过滤 1 2 3 4 5 6 SELECT subjectno,AVG (`studentresult`) FROM `result ` AS rGROUP BY `subjectno`HAVING AVG (`studentresult`)>= 70
事务 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 事务即多方同步操作 eg:转账,a给b转账,a-5000同时b+5000 遵守ACID原则: Atomicity 原子性 事务要么都成功,要么都失败,即操作同步。 当执行事务时有失败操作,可进行回滚,回到未改变的时候。这个还得靠我们主观判断。 Consistency 一致性 事务完成前后,数据库总量不变,执行前与执行后一致。 Isolation 隔离性 一个事务执行时不受其他事务影响。事务间隔离。 Durability 持久性 事务提交后不可逆,数据持久(永久)保存于数据库。 -- mysql默认开启事务 -- 手动处理事务,要先关闭自闭提交事务。 不然没法回滚。 SET autocommit = 0 -- 关闭自动提交 SET autocommit = 1 -- 开启自动提交(默认,即随时保存) START TRANSACTION; -- 开启事务 UPDATE information SET money=money-5 WHERE `name`='tang'; UPDATE information SET money=money+5 WHERE `name`='xxx'; COMMIT -- 提交 ROLLBACK -- 回滚 SAVEPOINT -- 设置保存点 ROLLBACK TO SAVEPOINT -- 回退到保存点 RELEASE SAVEPOINT -- --撤销、删除保存点 在并发下事务会产生的问题: 1、脏读 2、不可重复读 3、幻读 事务的隔离级别: 1、序列化 2、可重复读 3、提交读 4、未提交读
索引(INDEX) 1 2 MySQL官方对索引的定义为:索引(Index)是帮助MySQL高效获取数据的数据结构。 索引是为了提高数据检索能力而产生的。提高性能。
6.1、索引分类 1 2 3 4 5 6 7 8 9 主键索引(PRIMARY KEY) 唯一标识,不可重复。主键索引只能有一个。 唯一索引(UNIQUE) 索引的字段不重复,唯一索引可有多个。 普通索引(INDEX) 索引的字段可重复。 全文索引(FULLTEXT) 提高查询速度。 char、varchar、text类型 + MyISAM独有 #可能现在新版本没限制了
100万数据测试 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 CREATE TABLE `app_user` (`id` BIGINT (20 ) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR (50 ) DEFAULT '' COMMENT '用户昵称' , `email` VARCHAR (50 ) NOT NULL COMMENT '用户邮箱' , `phone` VARCHAR (20 ) DEFAULT '' COMMENT '手机号' , `gender` TINYINT(4 ) UNSIGNED DEFAULT '0' COMMENT '性别(0:男;1:女)' , `password` VARCHAR (100 ) NOT NULL COMMENT '密码' , `age` TINYINT(4 ) DEFAULT '0' COMMENT '年龄' , `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP , `update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP , PRIMARY KEY (`id`)) ENGINE= INNODB DEFAULT CHARSET= utf8mb4 COMMENT = 'app用户表' DELIMITER $$ CREATE FUNCTION mock_data ()RETURNS INT BEGIN DECLARE num INT DEFAULT 1000000 ; DECLARE i INT DEFAULT 0 ; WHILE i< num DO INSERT INTO `app_user`(`name`,`email`,`phone`,`gender`,`password`,`age`) VALUES (CONCAT('用户' ,i),'1262306856@qq.com' ,CONCAT('13' ,FLOOR (RAND() * ((999999999 -100000000 )+ 100000000 ))) ,FLOOR (RAND()* 2 ),UUID(),FLOOR (RAND()* 100 ) ); SET i= i+ 1 ; END WHILE; RETURN i; END ;SELECT mock_data() SELECT * FROM `app_user` WHERE `name`= '用户9999' ; CREATE INDEX id_app_user_name ON app_user(`name`);
数据库安全 用户管理 1 2 3 4 create user `用户名` identified by `密码` -- 创建用户 set password [for `用户`] = password(`密码`) -- 修改[当前]用户密码 rename user `旧名` to `新名` -- 修改用户名 drop user `用户` -- 删除用户
用户权限 1 2 3 4 grant all privileges on `数据库名.表名` to `用户` show grants for `用户` revoke all privileges on `数据库名.表名` from `用户`
数据库备份 1 2 3 4 1.物理备份 2.命令行指令: mysqldump -u `用户` -h `主机` -p `数据库` `表名` [表1 表2 表3] > `文件路径` 3.导入:source `文件路径`
三大范式 参考:https://www.cnblogs.com/wsg25/p/9615100.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 第一范式(1NF): 原子性:每一个字段不可再拆分。 第二范式(2NF): 前提:1NF 数据库表中每一个字段均和主键相关。 第三范式(3NF): 前提:1NF、2NF 数据表中每一个字段都和主键有直接相关,而不是间接相关。 三大范式用来规范数据库的设计 关联查询的表不超过3张: 考虑商业化的需求,数据库性能考虑更重要。 适当考虑规范性。 故意给某些表添加冗余字段。
JDBC Java database connect
相关jar包下载:
https://downloads.mysql.com/archives/c-j/
1 2 3 4 1、创建新工程,新建lib文件夹(library) 2、copy粘贴jar包到lib 3、右键lib,add as Library 导入成功后便可使用
模板 DriverManager 1 2 3 4 5 6 7 8 9 10 class.forName("com.mysql.jdbc.Driver" ); Connection connection = DriverManager.getConnection(url,username,password);
URL 1 2 3 4 String url = "jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=true" ;
Statement(重要!!!) 1 2 3 4 5 statement.executeQuery(); statement.execute(); statement.executeUpdate();
ResultSet 1 2 3 4 5 6 7 8 9 10 11 12 13 14 resultSet.getObject(); resultSet.getString(); resultSet.getInt(); resultSet.getDouble(); ····· resultSet.beforeFirst(); resultSet.afterLast(); resultSet.next(); resultSet.previous(); resultSet.absolute(row);
释放资源 1 2 3 4 resultSet.close(); statement.close(); connection.close();
Java代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 public static void main (String[] args) throws ClassNotFoundException, SQLException { Class.forName("com.mysql.jdbc.Driver" ); String url = "jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=true" ; String username = "root" ; String password = "111111" ; Connection connection = DriverManager.getConnection(url,username,password); Statement statement = connection.createStatement(); String sql = "SELECT * FROM users" ; ResultSet resultSet = statement.executeQuery(sql); while (resultSet.next()){ System.out.println("id=" + resultSet.getObject("id" )); System.out.println("NAME=" + resultSet.getObject("NAME" )); System.out.println("PASSWORD=" + resultSet.getObject("PASSWORD" )); System.out.println("email=" + resultSet.getObject("email" )); System.out.println("birthday=" + resultSet.getObject("birthday" )); } resultSet.close(); statement.close(); connection.close(); }
工具类实现及其他应用 工具类 1 2 3 4 5 ###db.properties driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=true username=root password=111111
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 public class JdbcUtils { private static String driver = null ; private static String url = null ; private static String username = null ; private static String password = null ; static { try { InputStream in = JdbcUtils.class.getClassLoader().getResourceAsStream("db.properties" ); Properties properties = new Properties(); properties.load(in); driver = properties.getProperty("driver" ); url = properties.getProperty("url" ); username = properties.getProperty("username" ); password = properties.getProperty("password" ); Class.forName(driver); }catch (Exception e){ e.printStackTrace(); } } public static Connection getConnection () throws SQLException { return DriverManager.getConnection(url,username,password); } public static void release (Connection connection, Statement statement, ResultSet resultSet) { if (resultSet!=null ){ try { resultSet.close(); }catch (SQLException e){ e.printStackTrace(); } } if (statement!=null ){ try { statement.close(); }catch (SQLException e){ e.printStackTrace(); } } if (connection!=null ){ try { connection.close(); }catch (SQLException e){ e.printStackTrace(); } } } }
增删改:executeUpdate 模板几乎一样,编写不同的sql语句然后调用即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 public class TEST { public static void main (String[] args) { Connection connection = null ; Statement statement = null ; ResultSet resultSet = null ; try { connection = JdbcUtils.getConnection(); statement = connection.createStatement(); String sql = "INSERT INTO users(id,`NAME`,`PASSWORD`,`email`,`birthday`)" + "VALUES(7,'s','sss','8888888','2555-08-24')" ; int i = statement.executeUpdate(sql); if (i>0 ){ System.out.println("成功插入" ); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(connection,statement,resultSet); } } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 public class TestDelete { public static void main (String[] args) { Connection connection = null ; Statement statement = null ; ResultSet resultSet = null ; try { connection = JdbcUtils.getConnection(); statement = connection.createStatement(); String sql = "delete from users where id=7" ; int i = statement.executeUpdate(sql); if (i>0 ){ System.out.println("删除了" ); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(connection,statement,resultSet); } } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 public class TestUpdata { public static void main (String[] args) { Connection connection = null ; Statement statement = null ; ResultSet resultSet = null ; try { connection = JdbcUtils.getConnection(); statement = connection.createStatement(); String sql = "update users set `NAME`='ttttt' where id=1" ; int i = statement.executeUpdate(sql); if (i>0 ){ System.out.println("修改成功" ); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(connection,statement,resultSet); } } }
查:executeQuery 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 public class TestSelect { public static void main (String[] args) { Connection connection = null ; Statement statement = null ; ResultSet resultSet = null ; try { connection = JdbcUtils.getConnection(); statement = connection.createStatement(); String sql = "select * from users where id=3" ; resultSet = statement.executeQuery(sql); while (resultSet.next()){ System.out.println(resultSet.getString("NAME" ) +"\n" + resultSet.getString("PASSWORD" )); } }catch (SQLException e){ e.printStackTrace(); }finally { JdbcUtils.release(connection,statement,resultSet); } } }
SQL注入 拼接sql语句,非法攻击,极其不安全。
解释:https://baike.baidu.com/item/sql%E6%B3%A8%E5%85%A5/150289?fr=aladdin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 public static void main (String[] args) { login("' or '1=1" ,"' or '1=1" ); } public static void login (String username,String password) { Connection connection = null ; Statement statement = null ; ResultSet resultSet = null ; try { connection = JdbcUtils.getConnection(); statement = connection.createStatement(); String sql = "select * from users where `NAME`='" +username+ "'and `PASSWORD` ='" +password+ "'" ; resultSet = statement.executeQuery(sql); while (resultSet.next()){ System.out.println(resultSet.getString("NAME" )); System.out.println(resultSet.getString("PASSWORD" )); } }catch (SQLException e){ e.printStackTrace(); }finally { JdbcUtils.release(connection,statement,resultSet); } }
PreparedStatement(更推荐使用) PreparedStatement可防止SQL注入,且执行效率更高。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 public static void main (String[] args) { Connection c = null ; PreparedStatement p = null ; ResultSet r = null ; try { c = JdbcUtils.getConnection(); String sql = "insert into users(`id`,`NAME`,`PASSWORD`,`email`,`birthday`) values(?,?,?,?,?)" ; p = c.prepareStatement(sql); p.setInt(1 ,8 ); p.setString(2 ,"xxxx" ); p.setString(3 ,"sdsdsdsd" ); p.setString(4 ,"88888@qq" ); p.setDate(5 ,new java.sql.Date(new Date().getTime())); int i = p.executeUpdate(); if (i>0 ){ System.out.println("插入成功" ); } }catch (SQLException e){ e.printStackTrace(); }finally { JdbcUtils.release(c,p,r); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 public static void main (String[] args) { Connection c = null ; PreparedStatement p = null ; ResultSet r = null ; try { c = JdbcUtils.getConnection(); String sql = "select * from users where id =?" ; p = c.prepareStatement(sql); p.setInt(1 ,1 ); r = p.executeQuery(); if (r.next()){ System.out.println(r.getString("NAME" )+"\n" +r.getString("email" )); } }catch (SQLException e){ e.printStackTrace(); }finally { JdbcUtils.release(c,p,r); } }
防止SQL注入 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 public static void main (String[] args) { login("'' or '1=1'" ,"'' or '1=1'" ); } public static void login (String username,String password) { Connection c = null ; PreparedStatement p = null ; ResultSet r = null ; try { c = JdbcUtils.getConnection(); String sql = "select * from users where `NAME`=? and `PASSWORD`=?" ; p=c.prepareStatement(sql); p.setString(1 ,username); p.setString(2 ,password); r = p.executeQuery(); while (r.next()){ System.out.println(r.getString("NAME" )); System.out.println(r.getString("email" )); } }catch (SQLException e){ e.printStackTrace(); }finally { JdbcUtils.release(c,p,r); } }
JDBC操作事务 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 public static void main (String[] args) { Connection c = null ; PreparedStatement p = null ; ResultSet r = null ; try { c = JdbcUtils.getConnection(); c.setAutoCommit(false ); String sql1 = "update account set money=money+100 where `name`='A'" ; p = c.prepareStatement(sql1); p.executeUpdate(); String sql2 = "update account set money=money-100 where `name`='B'" ; p = c.prepareStatement(sql2); p.executeUpdate(); c.commit(); System.out.println("修改好了" ); }catch (SQLException e){ e.printStackTrace(); }finally { JdbcUtils.release(c,p,r); } }
数据库连接池 使用连接池,不用自己编写连接数据库相关代码。
DBCP commons-dbcp-1.4.jar
commons-pool-1.6.jar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ###dbcpconfig.properties driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=true username=root password=111111 #初始化连接数 initialSize=10 #最大连接数 maxActive=50 #最大空闲连接 maxIdle=20 #最小空闲连接 minIdle=5 #最长等待超时时间 以毫秒为单位 maxWait=60000 connectionProperties=useUnicode=true;characterEncoding=UTF8 defaultAutoCommit=true defaultReadOnly= defaultTransactionIsolation=READ_UNCOMMITTED
工具类 使用连接池,不用自己去连接数据库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 private static DataSource dataSource = null ; static { try { InputStream in = JdbcUtils.class.getClassLoader().getResourceAsStream("dbcpconfig.properties" ); Properties properties = new Properties(); properties.load(in); dataSource = BasicDataSourceFactory.createDataSource(properties); }catch (Exception e){ e.printStackTrace(); } } public static Connection getConnection () throws SQLException { return dataSource.getConnection(); } public static void release (Connection connection, Statement statement, ResultSet resultSet) { if (resultSet!=null ){ try { resultSet.close(); }catch (SQLException e){ e.printStackTrace(); } } if (statement!=null ){ try { statement.close(); }catch (SQLException e){ e.printStackTrace(); } } if (connection!=null ){ try { connection.close(); }catch (SQLException e){ e.printStackTrace(); } } }
dbcp数据库功能使用 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 public static void main (String[] args) { Connection c = null ; PreparedStatement p = null ; try { c = DbcpUtils.getConnection(); String sql = "insert into users(`id`,`NAME`,`PASSWORD`,`email`,`birthday`) values(?,?,?,?,?)" ; p = c.prepareStatement(sql); p.setInt(1 ,10 ); p.setString(2 ,"x" ); p.setString(3 ,"sd" ); p.setString(4 ,"888@qq" ); p.setDate(5 ,new java.sql.Date(new Date().getTime())); int i = p.executeUpdate(); if (i>0 ){ System.out.println("插入成功" ); } }catch (SQLException e){ e.printStackTrace(); }finally { DbcpUtils.release(c,p,null ); } }
C3P0 c3p0-0.9.5.5.jar
mchange-commons-java-0.2.19.jar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ###c3p0-config.xml 注意c3p0配置文件是xml <?xml version="1.0" encoding="UTF-8"?> <c3p0-config> <default-config> <property name="driverClass">com.mysql.jdbc.Driver</property> <property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbcStudy?useUnicode=true&characterEncoding=utf-8</property> <property name="user">root</property> <property name="password">111111</property> <property name="acquireIncrement">5</property> <property name="initialPoolSize">10</property> <property name="minPoolSize">5</property> <property name="maxPoolSize">20</property> </default-config> <named-config name="MYSQL"> <property name="driverClass">com.mysql.jdbc.Driver</property> <property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbcStudy?useUnicode=true&characterEncoding=utf-8</property> <property name="user">root</property> <property name="password">111111</property> <property name="acquireIncrement">5</property> <property name="initialPoolSize">10</property> <property name="minPoolSize">5</property> <property name="maxPoolSize">20</property> </named-config> </c3p0-config>
小结 搞了半个月?总算是弄完数据库了,增删改查还要在今后的实践中熟练,下一站前端套餐走起。