feat: 更新示例

pull/32/merge
dunwu 2023-10-26 07:02:27 +08:00
parent 4c3ab73e81
commit 088d49c81f
18 changed files with 130 additions and 18 deletions

View File

@ -6,11 +6,15 @@ import org.junit.jupiter.api.Test;
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 <a href="mailto:forbreak@163.com">Zhang Peng</a>
* @see https://dev.mysql.com/doc/connector-j/5.1/en/
*/
public class MysqlDemoTest {

View File

@ -7,7 +7,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Zhang Peng
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
* @since 2018/6/19
*/
public class RedissonStandaloneTest {

View File

@ -15,7 +15,7 @@ import java.util.Set;
/**
* Jedis
*
* @author Zhang Peng
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
* @see https://github.com/xetorthio/jedis
*/
@Slf4j

View File

@ -16,7 +16,7 @@ import java.util.List;
import java.util.Set;
/**
* @author Zhang Peng
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("dev")

View File

@ -6,7 +6,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author Zhang Peng
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
* @since 2019-03-05
*/
@Slf4j

View File

@ -6,7 +6,7 @@ import java.sql.ResultSet;
import java.sql.Statement;
/**
* @author Zhang Peng
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
* @since 2019-03-05
*/
public class SqliteDemo {

View File

@ -1,7 +1,7 @@
-- --------------------------------------------------------------------------------------
-- 查找重复的电子邮箱
-- @link https://leetcode-cn.com/problems/duplicate-emails/
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2020/02/29
-- ----------------------------------------------------------------------------------------

View File

@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- Mysql 查询示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2018/5/5
-- ----------------------------------------------------------------------------------------

View File

@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- 函数操作影响索引效率示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- ----------------------------------------------------------------------------------------
-- 步骤 1、建表

View File

@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- 函数操作影响索引效率示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- ----------------------------------------------------------------------------------------
CREATE TABLE t (

View File

@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- Mysql 事务示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2020/02/29
-- ----------------------------------------------------------------------------------------

View File

@ -0,0 +1,55 @@
-- --------------------------------------------------------------------------------------
-- 幻读示例
-- 实验说明:以下 SQL 脚本必须严格按照顺序执行,并且事务 A 和事务 B 必须在不同的 Client 中执行。
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @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;

View File

@ -0,0 +1,53 @@
-- --------------------------------------------------------------------------------------
-- 幻读示例
-- 实验说明:以下 SQL 脚本必须严格按照顺序执行,并且事务 A 和事务 B 必须在不同的 Client 中执行。
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @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;

View File

@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- Mysql 基本 DDL 语句示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2018/4/28
-- ----------------------------------------------------------------------------------------

View File

@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- Mysql 基本 DML 语句示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2018/4/28
-- ----------------------------------------------------------------------------------------

View File

@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- Mysql 基本 TCL 语句示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2018/4/28
-- ----------------------------------------------------------------------------------------

View File

@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- Mysql 常见查询示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2018/5/4
-- ----------------------------------------------------------------------------------------

View File

@ -1,11 +1,11 @@
/**
* Mysql TRIGGER使
* @author Zhang Peng
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
* @date 2018/5/2
*/
-- --------------------------------------------------------------------------------------
-- Mysql 基本 DDL 语句示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2018/4/28
-- ----------------------------------------------------------------------------------------