diff --git a/codes/javadb/README.md b/codes/javadb/README.md new file mode 100644 index 0000000..55ca9f4 --- /dev/null +++ b/codes/javadb/README.md @@ -0,0 +1,3 @@ +# javadb + +> 本目录中存放在 Java 中操作各数据库的示例(未使用 ORM)。 diff --git a/codes/javadb/javadb-mysql/pom.xml b/codes/javadb/javadb-mysql/pom.xml new file mode 100644 index 0000000..3973567 --- /dev/null +++ b/codes/javadb/javadb-mysql/pom.xml @@ -0,0 +1,113 @@ + + + 4.0.0 + io.github.dunwu + javadb-mysql + 1.0.0 + jar + + + UTF-8 + 1.8 + ${java.version} + ${java.version} + + 4.3.13.RELEASE + 1.2.3 + 4.12 + + + + + + mysql + mysql-connector-java + 5.1.45 + + + org.apache.commons + commons-pool2 + 2.5.0 + + + + + + ch.qos.logback + logback-classic + + + + + + org.springframework + spring-context-support + + + org.springframework + spring-test + test + + + + + + junit + junit + + + + + + + + org.springframework + spring-framework-bom + ${spring.version} + pom + import + + + + + redis.clients + jedis + ${jedis.version} + + + + + + ch.qos.logback + logback-parent + ${logback.version} + pom + import + + + + + + junit + junit + ${junit.version} + test + + + + + + + ${project.artifactId} + + + true + src/main/resources + + logback.xml + + + + + diff --git a/codes/javadb/mysql/src/test/java/io/github/dunwu/javadb/MysqlDemoTest.java b/codes/javadb/javadb-mysql/src/test/java/io/github/dunwu/javadb/MysqlDemoTest.java similarity index 96% rename from codes/javadb/mysql/src/test/java/io/github/dunwu/javadb/MysqlDemoTest.java rename to codes/javadb/javadb-mysql/src/test/java/io/github/dunwu/javadb/MysqlDemoTest.java index 20022da..5ea5da2 100644 --- a/codes/javadb/mysql/src/test/java/io/github/dunwu/javadb/MysqlDemoTest.java +++ b/codes/javadb/javadb-mysql/src/test/java/io/github/dunwu/javadb/MysqlDemoTest.java @@ -14,7 +14,6 @@ import org.slf4j.LoggerFactory; /** * Mysql 测试例 - * * @author Zhang Peng * @see https://dev.mysql.com/doc/connector-j/5.1/en/ */ @@ -35,7 +34,8 @@ public class MysqlDemoTest { try { final String DB_URL = String.format("jdbc:mysql://%s:%s/%s", DB_HOST, DB_PORT, DB_SCHEMA); connection = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD); - // connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sakila?" + "user=root&password=root"); + // connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sakila?" + + // "user=root&password=root"); statement = connection.createStatement(); } catch (SQLException e) { e.printStackTrace(); diff --git a/codes/javadb/mysql/src/test/resources/logback.xml b/codes/javadb/javadb-mysql/src/test/resources/logback.xml similarity index 100% rename from codes/javadb/mysql/src/test/resources/logback.xml rename to codes/javadb/javadb-mysql/src/test/resources/logback.xml diff --git a/codes/javadb/javadb-redis-jedis/pom.xml b/codes/javadb/javadb-redis-jedis/pom.xml new file mode 100644 index 0000000..d496619 --- /dev/null +++ b/codes/javadb/javadb-redis-jedis/pom.xml @@ -0,0 +1,108 @@ + + + 4.0.0 + io.github.dunwu + javadb-redis-jedis + 1.0.0 + jar + + + UTF-8 + 1.8 + ${java.version} + ${java.version} + + 4.3.13.RELEASE + 1.2.3 + 2.9.0 + 4.12 + + + + + + redis.clients + jedis + + + + + + ch.qos.logback + logback-classic + + + + + + org.springframework + spring-context-support + + + org.springframework + spring-test + test + + + + + + junit + junit + + + + + + + + org.springframework + spring-framework-bom + ${spring.version} + pom + import + + + + + redis.clients + jedis + ${jedis.version} + + + + + + ch.qos.logback + logback-parent + ${logback.version} + pom + import + + + + + + junit + junit + ${junit.version} + test + + + + + + + ${project.artifactId} + + + true + src/main/resources + + logback.xml + + + + + diff --git a/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/JedisDemoTest.java b/codes/javadb/javadb-redis-jedis/src/test/java/io/github/dunwu/javadb/JedisDemoTest.java similarity index 98% rename from codes/javadb/redis/src/test/java/io/github/dunwu/javadb/JedisDemoTest.java rename to codes/javadb/javadb-redis-jedis/src/test/java/io/github/dunwu/javadb/JedisDemoTest.java index 883a557..e5ad437 100644 --- a/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/JedisDemoTest.java +++ b/codes/javadb/javadb-redis-jedis/src/test/java/io/github/dunwu/javadb/JedisDemoTest.java @@ -3,24 +3,22 @@ package io.github.dunwu.javadb; import java.util.List; import java.util.Map; import java.util.Set; - import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import redis.clients.jedis.Jedis; import redis.clients.jedis.exceptions.JedisConnectionException; /** * Jedis 测试例 - * @see https://github.com/xetorthio/jedis * @author Zhang Peng + * @see https://github.com/xetorthio/jedis */ public class JedisDemoTest { - private static final String REDIS_HOST = "192.168.58.170"; + private static final String REDIS_HOST = "192.168.28.32"; private static final int REDIS_PORT = 6379; private static Jedis jedis = null; private static Logger logger = LoggerFactory.getLogger(JedisDemoTest.class); diff --git a/codes/javadb/redis/src/test/java/io/github/dunwu/javadb/JedisPoolDemoTest.java b/codes/javadb/javadb-redis-jedis/src/test/java/io/github/dunwu/javadb/JedisPoolDemoTest.java similarity index 100% rename from codes/javadb/redis/src/test/java/io/github/dunwu/javadb/JedisPoolDemoTest.java rename to codes/javadb/javadb-redis-jedis/src/test/java/io/github/dunwu/javadb/JedisPoolDemoTest.java diff --git a/codes/javadb/redis/src/test/resources/applicationContext.xml b/codes/javadb/javadb-redis-jedis/src/test/resources/applicationContext.xml similarity index 100% rename from codes/javadb/redis/src/test/resources/applicationContext.xml rename to codes/javadb/javadb-redis-jedis/src/test/resources/applicationContext.xml diff --git a/codes/javadb/redis/src/test/resources/config.xml b/codes/javadb/javadb-redis-jedis/src/test/resources/config.xml similarity index 100% rename from codes/javadb/redis/src/test/resources/config.xml rename to codes/javadb/javadb-redis-jedis/src/test/resources/config.xml diff --git a/codes/javadb/redis/src/test/resources/logback.xml b/codes/javadb/javadb-redis-jedis/src/test/resources/logback.xml similarity index 93% rename from codes/javadb/redis/src/test/resources/logback.xml rename to codes/javadb/javadb-redis-jedis/src/test/resources/logback.xml index 143ac56..a343b51 100644 --- a/codes/javadb/redis/src/test/resources/logback.xml +++ b/codes/javadb/javadb-redis-jedis/src/test/resources/logback.xml @@ -16,7 +16,7 @@ - ${user.dir}/logs/${FILE_NAME}-all.%d{yyyy-MM-dd}.log + ${user.dir}/logs/${FILE_NAME}.%d{yyyy-MM-dd}.log 30 diff --git a/codes/javadb/redis/src/test/resources/properties/application-dev.properties b/codes/javadb/javadb-redis-jedis/src/test/resources/properties/application-dev.properties similarity index 100% rename from codes/javadb/redis/src/test/resources/properties/application-dev.properties rename to codes/javadb/javadb-redis-jedis/src/test/resources/properties/application-dev.properties diff --git a/codes/javadb/redis/src/test/resources/properties/application-test.properties b/codes/javadb/javadb-redis-jedis/src/test/resources/properties/application-test.properties similarity index 81% rename from codes/javadb/redis/src/test/resources/properties/application-test.properties rename to codes/javadb/javadb-redis-jedis/src/test/resources/properties/application-test.properties index 1043bd4..6a05459 100644 --- a/codes/javadb/redis/src/test/resources/properties/application-test.properties +++ b/codes/javadb/javadb-redis-jedis/src/test/resources/properties/application-test.properties @@ -1,5 +1,5 @@ redis.name=redis-default -redis.host=192.168.58.170 +redis.host=192.168.28.32 redis.port=6379 redis.timeout=3000 redis.password=zp diff --git a/codes/javadb/redis/src/test/resources/properties/application.properties b/codes/javadb/javadb-redis-jedis/src/test/resources/properties/application.properties similarity index 100% rename from codes/javadb/redis/src/test/resources/properties/application.properties rename to codes/javadb/javadb-redis-jedis/src/test/resources/properties/application.properties diff --git a/codes/javadb/redis/src/test/resources/redis.xml b/codes/javadb/javadb-redis-jedis/src/test/resources/redis.xml similarity index 100% rename from codes/javadb/redis/src/test/resources/redis.xml rename to codes/javadb/javadb-redis-jedis/src/test/resources/redis.xml diff --git a/codes/javadb/mysql/pom.xml b/codes/javadb/mysql/pom.xml deleted file mode 100644 index c3729bf..0000000 --- a/codes/javadb/mysql/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - 4.0.0 - - - - - - javadb-mysql - jar - - - - - io.github.dunwu - javadb - 1.0.0 - - - - - mysql - mysql-connector-java - 5.1.45 - - - org.apache.commons - commons-pool2 - 2.5.0 - - - - - - ch.qos.logback - logback-classic - - - - - org.springframework - spring-context-support - - - org.springframework - spring-test - test - - - - - - - - - - ${project.artifactId} - - - true - src/main/resources - - logback.xml - - - - - - - - - - ${project.artifactId} - Java 工具使用示例 - - - - diff --git a/codes/javadb/pom.xml b/codes/javadb/pom.xml deleted file mode 100644 index e682895..0000000 --- a/codes/javadb/pom.xml +++ /dev/null @@ -1,110 +0,0 @@ - - - 4.0.0 - - - - - - io.github.dunwu - javadb - 1.0.0 - pom - - - - - redis - mysql - - - - - - - junit - junit - 4.12 - test - - - - - - - org.springframework - spring-framework-bom - ${spring.version} - pom - import - - - - - - ch.qos.logback - logback-parent - ${logback.version} - pom - import - - - org.logback-extensions - logback-ext-spring - 0.1.2 - - - org.slf4j - jcl-over-slf4j - 1.7.12 - - - - - - javax.servlet - javax.servlet-api - 3.1.0 - provided - - - javax.servlet.jsp - jsp-api - 2.2 - provided - - - - - - - - - UTF-8 - 1.8 - ${java.version} - ${java.version} - - 4.3.13.RELEASE - 1.2.3 - - - - - - - - - ${project.artifactId} - - - - - - ${project.artifactId} - Java 工具使用示例 - - - - diff --git a/codes/javadb/redis/pom.xml b/codes/javadb/redis/pom.xml deleted file mode 100644 index 79b63a7..0000000 --- a/codes/javadb/redis/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - 4.0.0 - - - - - - javadb-redis - jar - - - - - io.github.dunwu - javadb - 1.0.0 - - - - - redis.clients - jedis - 2.9.0 - - - - - - ch.qos.logback - logback-classic - - - - - org.springframework - spring-context-support - - - org.springframework - spring-test - test - - - - - - - - - - ${project.artifactId} - - - true - src/main/resources - - logback.xml - - - - - - - - - - ${project.artifactId} - Java 工具使用示例 - - - - diff --git a/codes/sql/sql_constraint_demo.sql b/codes/sql/sql_constraint_demo.sql deleted file mode 100644 index 89e640e..0000000 --- a/codes/sql/sql_constraint_demo.sql +++ /dev/null @@ -1,68 +0,0 @@ -/* - sql 约束的 Mysql 示例 - */ - --- -------------------------------------------------------------- --- DDL BEGIN --- -------------------------------------------------------------- - --- NOT NULL 约束 -DROP TABLE IF EXISTS person; -CREATE TABLE person ( - person_id INT NOT NULL, - name VARCHAR(255) NOT NULL, - age INT, - address VARCHAR(255) -); - --- UNIQUE 约束 -DROP TABLE IF EXISTS person; -CREATE TABLE person ( - person_id INT NOT NULL, - name VARCHAR(255) NOT NULL, - age INT, - address VARCHAR(255), - UNIQUE (person_id) -); - --- PRIMARY KEY 约束 -DROP TABLE IF EXISTS person; -CREATE TABLE person ( - person_id INT NOT NULL PRIMARY KEY, - name VARCHAR(255) NOT NULL, - age INT, - address VARCHAR(255) -); - --- FOREIGN KEY 约束 -DROP TABLE IF EXISTS bill; -CREATE TABLE bill -( - bill_id INT NOT NULL, - bill_no INT NOT NULL, - person_id INT, - PRIMARY KEY (bill_id), - FOREIGN KEY (person_id) REFERENCES person(person_id) -); - --- CHECK 约束 -DROP TABLE IF EXISTS person; -CREATE TABLE person ( - person_id INT NOT NULL, - name VARCHAR(255) NOT NULL, - age INT CHECK (age >= 18), - address VARCHAR(255) -); - --- DEFAULT 约束 -DROP TABLE IF EXISTS person; -CREATE TABLE person ( - person_id INT NOT NULL, - name VARCHAR(255) NOT NULL, - age INT DEFAULT 18, - address VARCHAR(255) -); - --- -------------------------------------------------------------- --- DDL END --- -------------------------------------------------------------- \ No newline at end of file