diff --git a/codes/javadb/mysql/src/test/java/io/github/dunwu/javadb/mysql/springboot/MysqlDemoTest.java b/codes/javadb/mysql/src/test/java/io/github/dunwu/javadb/mysql/springboot/MysqlDemoTest.java index c8a2236d..6b0f2dbf 100644 --- a/codes/javadb/mysql/src/test/java/io/github/dunwu/javadb/mysql/springboot/MysqlDemoTest.java +++ b/codes/javadb/mysql/src/test/java/io/github/dunwu/javadb/mysql/springboot/MysqlDemoTest.java @@ -6,11 +6,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; /** * Mysql 测试例 - * @author Zhang Peng + * @author Zhang Peng * @see https://dev.mysql.com/doc/connector-j/5.1/en/ */ public class MysqlDemoTest { diff --git a/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/redis/RedissonStandaloneTest.java b/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/redis/RedissonStandaloneTest.java index cf04e72f..f483c9a1 100644 --- a/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/redis/RedissonStandaloneTest.java +++ b/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/redis/RedissonStandaloneTest.java @@ -7,7 +7,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; /** - * @author Zhang Peng + * @author Zhang Peng * @since 2018/6/19 */ public class RedissonStandaloneTest { diff --git a/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/redis/jedis/JedisDemoTest.java b/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/redis/jedis/JedisDemoTest.java index 18126676..a48d1ea2 100644 --- a/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/redis/jedis/JedisDemoTest.java +++ b/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/redis/jedis/JedisDemoTest.java @@ -15,7 +15,7 @@ /** * Jedis 测试例 * - * @author Zhang Peng + * @author Zhang Peng * @see https://github.com/xetorthio/jedis */ @Slf4j diff --git a/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/redis/jedis/JedisPoolDemoTest.java b/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/redis/jedis/JedisPoolDemoTest.java index d39ea123..9b693bad 100644 --- a/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/redis/jedis/JedisPoolDemoTest.java +++ b/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/redis/jedis/JedisPoolDemoTest.java @@ -16,7 +16,7 @@ import java.util.Set; /** - * @author Zhang Peng + * @author Zhang Peng */ @RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles("dev") diff --git a/codes/javadb/sqlite/src/main/java/io/github/dunwu/javadb/sqlite/springboot/SpringBootDataSqliteApplication.java b/codes/javadb/sqlite/src/main/java/io/github/dunwu/javadb/sqlite/springboot/SpringBootDataSqliteApplication.java index e7fad56e..3870e9b9 100644 --- a/codes/javadb/sqlite/src/main/java/io/github/dunwu/javadb/sqlite/springboot/SpringBootDataSqliteApplication.java +++ b/codes/javadb/sqlite/src/main/java/io/github/dunwu/javadb/sqlite/springboot/SpringBootDataSqliteApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; /** - * @author Zhang Peng + * @author Zhang Peng * @since 2019-03-05 */ @Slf4j diff --git a/codes/javadb/sqlite/src/main/java/io/github/dunwu/javadb/sqlite/springboot/SqliteDemo.java b/codes/javadb/sqlite/src/main/java/io/github/dunwu/javadb/sqlite/springboot/SqliteDemo.java index b2ac44f7..fac342d3 100644 --- a/codes/javadb/sqlite/src/main/java/io/github/dunwu/javadb/sqlite/springboot/SqliteDemo.java +++ b/codes/javadb/sqlite/src/main/java/io/github/dunwu/javadb/sqlite/springboot/SqliteDemo.java @@ -6,7 +6,7 @@ import java.sql.Statement; /** - * @author Zhang Peng + * @author Zhang Peng * @since 2019-03-05 */ public class SqliteDemo { diff --git "a/codes/mysql/Leetcode\344\271\213SQL\351\242\230/easy/\346\237\245\346\211\276\351\207\215\345\244\215\347\232\204\347\224\265\345\255\220\351\202\256\347\256\261.sql" "b/codes/mysql/Leetcode\344\271\213SQL\351\242\230/easy/\346\237\245\346\211\276\351\207\215\345\244\215\347\232\204\347\224\265\345\255\220\351\202\256\347\256\261.sql" index 0567c469..6b59150a 100644 --- "a/codes/mysql/Leetcode\344\271\213SQL\351\242\230/easy/\346\237\245\346\211\276\351\207\215\345\244\215\347\232\204\347\224\265\345\255\220\351\202\256\347\256\261.sql" +++ "b/codes/mysql/Leetcode\344\271\213SQL\351\242\230/easy/\346\237\245\346\211\276\351\207\215\345\244\215\347\232\204\347\224\265\345\255\220\351\202\256\347\256\261.sql" @@ -1,7 +1,7 @@ -- -------------------------------------------------------------------------------------- -- 查找重复的电子邮箱 -- @link https://leetcode-cn.com/problems/duplicate-emails/ --- @author Zhang Peng +-- @author Zhang Peng -- @date 2020/02/29 -- ---------------------------------------------------------------------------------------- diff --git "a/codes/mysql/SQL\345\277\205\347\237\245\345\277\205\344\274\232\347\244\272\344\276\213/select.sql" "b/codes/mysql/SQL\345\277\205\347\237\245\345\277\205\344\274\232\347\244\272\344\276\213/select.sql" index 9f63a09a..6ec69d84 100644 --- "a/codes/mysql/SQL\345\277\205\347\237\245\345\277\205\344\274\232\347\244\272\344\276\213/select.sql" +++ "b/codes/mysql/SQL\345\277\205\347\237\245\345\277\205\344\274\232\347\244\272\344\276\213/select.sql" @@ -1,6 +1,6 @@ -- -------------------------------------------------------------------------------------- -- Mysql 查询示例 --- @author Zhang Peng +-- @author Zhang Peng -- @date 2018/5/5 -- ---------------------------------------------------------------------------------------- diff --git "a/codes/mysql/SQL\346\200\247\350\203\275\344\274\230\345\214\226/SQL\345\207\275\346\225\260\345\275\261\345\223\215\347\264\242\345\274\225.sql" "b/codes/mysql/SQL\346\200\247\350\203\275\344\274\230\345\214\226/SQL\345\207\275\346\225\260\345\275\261\345\223\215\347\264\242\345\274\225.sql" index 1420f991..577ec893 100644 --- "a/codes/mysql/SQL\346\200\247\350\203\275\344\274\230\345\214\226/SQL\345\207\275\346\225\260\345\275\261\345\223\215\347\264\242\345\274\225.sql" +++ "b/codes/mysql/SQL\346\200\247\350\203\275\344\274\230\345\214\226/SQL\345\207\275\346\225\260\345\275\261\345\223\215\347\264\242\345\274\225.sql" @@ -1,6 +1,6 @@ -- -------------------------------------------------------------------------------------- -- 函数操作影响索引效率示例 --- @author Zhang Peng +-- @author Zhang Peng -- ---------------------------------------------------------------------------------------- -- 步骤 1、建表 diff --git "a/codes/mysql/SQL\346\200\247\350\203\275\344\274\230\345\214\226/\347\255\211MDL\351\224\201.sql" "b/codes/mysql/SQL\346\200\247\350\203\275\344\274\230\345\214\226/\347\255\211MDL\351\224\201.sql" index 1270ad42..67acf42c 100644 --- "a/codes/mysql/SQL\346\200\247\350\203\275\344\274\230\345\214\226/\347\255\211MDL\351\224\201.sql" +++ "b/codes/mysql/SQL\346\200\247\350\203\275\344\274\230\345\214\226/\347\255\211MDL\351\224\201.sql" @@ -1,6 +1,6 @@ -- -------------------------------------------------------------------------------------- -- 函数操作影响索引效率示例 --- @author Zhang Peng +-- @author Zhang Peng -- ---------------------------------------------------------------------------------------- CREATE TABLE t ( diff --git "a/codes/mysql/\344\272\213\345\212\241\347\244\272\344\276\213.sql" "b/codes/mysql/\344\272\213\345\212\241/\344\272\213\345\212\241\347\244\272\344\276\213.sql" similarity index 95% rename from "codes/mysql/\344\272\213\345\212\241\347\244\272\344\276\213.sql" rename to "codes/mysql/\344\272\213\345\212\241/\344\272\213\345\212\241\347\244\272\344\276\213.sql" index 10f3fdac..5dfde103 100644 --- "a/codes/mysql/\344\272\213\345\212\241\347\244\272\344\276\213.sql" +++ "b/codes/mysql/\344\272\213\345\212\241/\344\272\213\345\212\241\347\244\272\344\276\213.sql" @@ -1,6 +1,6 @@ -- -------------------------------------------------------------------------------------- -- Mysql 事务示例 --- @author Zhang Peng +-- @author Zhang Peng -- @date 2020/02/29 -- ---------------------------------------------------------------------------------------- diff --git "a/codes/mysql/\344\272\213\345\212\241/\345\271\273\350\257\273\347\244\272\344\276\2131.sql" "b/codes/mysql/\344\272\213\345\212\241/\345\271\273\350\257\273\347\244\272\344\276\2131.sql" new file mode 100644 index 00000000..55467a1e --- /dev/null +++ "b/codes/mysql/\344\272\213\345\212\241/\345\271\273\350\257\273\347\244\272\344\276\2131.sql" @@ -0,0 +1,55 @@ +-- -------------------------------------------------------------------------------------- +-- 幻读示例 +-- 实验说明:以下 SQL 脚本必须严格按照顺序执行,并且事务 A 和事务 B 必须在不同的 Client 中执行。 +-- @author Zhang Peng +-- @date 2023/10/25 +-- ---------------------------------------------------------------------------------------- + +-- --------------------------------------------------------------------- (1)数据初始化 + +-- 创建表 test +CREATE TABLE `test` ( + `id` INT(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT, + `value` INT(10) NOT NULL +); + +-- 数据初始化 +INSERT INTO `test` (`id`, `value`) VALUES (1, 1); +INSERT INTO `test` (`id`, `value`) VALUES (2, 2); +INSERT INTO `test` (`id`, `value`) VALUES (3, 3); + +-- --------------------------------------------------------------------- (2)事务 A + +BEGIN; + +-- 查询 id = 4 的记录 +SELECT * FROM `test` WHERE `id` = 4; +-- 结果为空 + +-- --------------------------------------------------------------------- (3)事务 B + +BEGIN; + +INSERT INTO `test` (`id`, `value`) VALUES (4, 4); + +COMMIT; + +-- --------------------------------------------------------------------- (4)事务 A + +-- 查询 id = 4 的记录 +SELECT * FROM `test` WHERE `id` = 4; +-- 结果依然为空 + +-- 成功更新本应看不到的记录 id = 4 +UPDATE `test` SET `value` = 0 WHERE `id` = 4; + +-- 再一次查询 id = 4 的记录 +SELECT * FROM `test` WHERE `id` = 4; +-- 结果为: +-- +----+-------+ +-- | id | value | +-- +----+-------+ +-- | 4 | 0 | +-- +----+-------+ + +COMMIT; \ No newline at end of file diff --git "a/codes/mysql/\344\272\213\345\212\241/\345\271\273\350\257\273\347\244\272\344\276\2132.sql" "b/codes/mysql/\344\272\213\345\212\241/\345\271\273\350\257\273\347\244\272\344\276\2132.sql" new file mode 100644 index 00000000..2bb125d7 --- /dev/null +++ "b/codes/mysql/\344\272\213\345\212\241/\345\271\273\350\257\273\347\244\272\344\276\2132.sql" @@ -0,0 +1,53 @@ +-- -------------------------------------------------------------------------------------- +-- 幻读示例 +-- 实验说明:以下 SQL 脚本必须严格按照顺序执行,并且事务 A 和事务 B 必须在不同的 Client 中执行。 +-- @author Zhang Peng +-- @date 2023/10/25 +-- ---------------------------------------------------------------------------------------- + +-- --------------------------------------------------------------------- (1)数据初始化 + +-- 创建表 test +CREATE TABLE `test` ( + `id` INT(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT, + `value` INT(10) NOT NULL +); + +-- 数据初始化 +INSERT INTO `test` (`id`, `value`) VALUES (1, 1); +INSERT INTO `test` (`id`, `value`) VALUES (2, 2); +INSERT INTO `test` (`id`, `value`) VALUES (3, 3); + +-- --------------------------------------------------------------------- (2)事务 A + +BEGIN; + +-- 查询 id > 2 的记录数 +SELECT COUNT(*) FROM `test` WHERE `id` > 2; +-- 结果为: +-- +----------+ +-- | count(*) | +-- +----------+ +-- | 1 | +-- +----------+ + +-- --------------------------------------------------------------------- (3)事务 B + +BEGIN; + +INSERT INTO `test` (`id`, `value`) VALUES (4, 4); + +COMMIT; + +-- --------------------------------------------------------------------- (4)事务 A + +-- 查询 id = 4 的记录 +SELECT COUNT(*) FROM `test` WHERE `id` > 2 FOR UPDATE; +-- 结果为: +-- +----------+ +-- | count(*) | +-- +----------+ +-- | 2 | +-- +----------+ + +COMMIT; \ No newline at end of file diff --git "a/codes/mysql/\345\237\272\346\234\254DDL\347\244\272\344\276\213.sql" "b/codes/mysql/\345\237\272\346\234\254DDL\347\244\272\344\276\213.sql" index 894b933f..608c9605 100644 --- "a/codes/mysql/\345\237\272\346\234\254DDL\347\244\272\344\276\213.sql" +++ "b/codes/mysql/\345\237\272\346\234\254DDL\347\244\272\344\276\213.sql" @@ -1,6 +1,6 @@ -- -------------------------------------------------------------------------------------- -- Mysql 基本 DDL 语句示例 --- @author Zhang Peng +-- @author Zhang Peng -- @date 2018/4/28 -- ---------------------------------------------------------------------------------------- diff --git "a/codes/mysql/\345\237\272\346\234\254DML\347\244\272\344\276\213.sql" "b/codes/mysql/\345\237\272\346\234\254DML\347\244\272\344\276\213.sql" index b0db5628..11c3bd2e 100644 --- "a/codes/mysql/\345\237\272\346\234\254DML\347\244\272\344\276\213.sql" +++ "b/codes/mysql/\345\237\272\346\234\254DML\347\244\272\344\276\213.sql" @@ -1,6 +1,6 @@ -- -------------------------------------------------------------------------------------- -- Mysql 基本 DML 语句示例 --- @author Zhang Peng +-- @author Zhang Peng -- @date 2018/4/28 -- ---------------------------------------------------------------------------------------- diff --git "a/codes/mysql/\345\237\272\346\234\254TCL\347\244\272\344\276\213.sql" "b/codes/mysql/\345\237\272\346\234\254TCL\347\244\272\344\276\213.sql" index 28c55dd5..013a5188 100644 --- "a/codes/mysql/\345\237\272\346\234\254TCL\347\244\272\344\276\213.sql" +++ "b/codes/mysql/\345\237\272\346\234\254TCL\347\244\272\344\276\213.sql" @@ -1,6 +1,6 @@ -- -------------------------------------------------------------------------------------- -- Mysql 基本 TCL 语句示例 --- @author Zhang Peng +-- @author Zhang Peng -- @date 2018/4/28 -- ---------------------------------------------------------------------------------------- diff --git "a/codes/mysql/\345\270\270\350\247\201\346\237\245\350\257\242\347\244\272\344\276\213.sql" "b/codes/mysql/\345\270\270\350\247\201\346\237\245\350\257\242\347\244\272\344\276\213.sql" index f6a843c1..a079f543 100644 --- "a/codes/mysql/\345\270\270\350\247\201\346\237\245\350\257\242\347\244\272\344\276\213.sql" +++ "b/codes/mysql/\345\270\270\350\247\201\346\237\245\350\257\242\347\244\272\344\276\213.sql" @@ -1,6 +1,6 @@ -- -------------------------------------------------------------------------------------- -- Mysql 常见查询示例 --- @author Zhang Peng +-- @author Zhang Peng -- @date 2018/5/4 -- ---------------------------------------------------------------------------------------- diff --git "a/codes/mysql/\350\247\246\345\217\221\345\231\250\347\244\272\344\276\213.sql" "b/codes/mysql/\350\247\246\345\217\221\345\231\250\347\244\272\344\276\213.sql" index f9337eb9..d36d9183 100644 --- "a/codes/mysql/\350\247\246\345\217\221\345\231\250\347\244\272\344\276\213.sql" +++ "b/codes/mysql/\350\247\246\345\217\221\345\231\250\347\244\272\344\276\213.sql" @@ -1,11 +1,11 @@ /** * Mysql 触发器(TRIGGER)创建、使用示例 - * @author Zhang Peng + * @author Zhang Peng * @date 2018/5/2 */ -- -------------------------------------------------------------------------------------- -- Mysql 基本 DDL 语句示例 --- @author Zhang Peng +-- @author Zhang Peng -- @date 2018/4/28 -- ----------------------------------------------------------------------------------------