diff --git a/hutool-db/pom.xml b/hutool-db/pom.xml
index 6bdf09299..2312adac4 100644
--- a/hutool-db/pom.xml
+++ b/hutool-db/pom.xml
@@ -135,5 +135,11 @@
1.7.26
test
+
+ com.h2database
+ h2
+ 1.4.200
+ test
+
diff --git a/hutool-db/src/main/java/cn/hutool/db/dialect/DialectFactory.java b/hutool-db/src/main/java/cn/hutool/db/dialect/DialectFactory.java
index 05484d09a..8995d0f39 100644
--- a/hutool-db/src/main/java/cn/hutool/db/dialect/DialectFactory.java
+++ b/hutool-db/src/main/java/cn/hutool/db/dialect/DialectFactory.java
@@ -45,9 +45,7 @@ public class DialectFactory {
/** JDBC 驱动 H2 */
public static final String DRIVER_H2 = "org.h2.Driver";
/** JDBC 驱动 Derby */
- public static final String DRIVER_DERBY = "org.apache.derby.jdbc.ClientDriver";
- /** JDBC 驱动 Derby嵌入式 */
- public static final String DRIVER_DERBY_EMBEDDED = "org.apache.derby.jdbc.EmbeddedDriver";
+ public static final String DRIVER_DERBY = "org.apache.derby.jdbc.AutoloadedDriver";
/** JDBC 驱动 HSQLDB */
public static final String DRIVER_HSQLDB = "org.hsqldb.jdbc.JDBCDriver";
/** JDBC 驱动 达梦7 */
@@ -126,12 +124,9 @@ public class DialectFactory {
driver = DRIVER_HIVE;
} else if (nameContainsProductInfo.contains("h2")) {
driver = DRIVER_H2;
- } else if (nameContainsProductInfo.startsWith("jdbc:derby://")) {
- // Derby数据库网络连接方式
- driver = DRIVER_DERBY;
} else if (nameContainsProductInfo.contains("derby")) {
// 嵌入式Derby数据库
- driver = DRIVER_DERBY_EMBEDDED;
+ driver = DRIVER_DERBY;
} else if (nameContainsProductInfo.contains("hsqldb")) {
// HSQLDB
driver = DRIVER_HSQLDB;
diff --git a/hutool-db/src/main/java/cn/hutool/db/dialect/impl/H2Dialect.java b/hutool-db/src/main/java/cn/hutool/db/dialect/impl/H2Dialect.java
index 0d86f061a..404814c45 100644
--- a/hutool-db/src/main/java/cn/hutool/db/dialect/impl/H2Dialect.java
+++ b/hutool-db/src/main/java/cn/hutool/db/dialect/impl/H2Dialect.java
@@ -3,19 +3,17 @@ package cn.hutool.db.dialect.impl;
import cn.hutool.db.Page;
import cn.hutool.db.dialect.DialectName;
import cn.hutool.db.sql.SqlBuilder;
-import cn.hutool.db.sql.Wrapper;
/**
* H2数据库方言
- *
- * @author loolly
*
+ * @author loolly
*/
public class H2Dialect extends AnsiSqlDialect {
private static final long serialVersionUID = 1490520247974768214L;
public H2Dialect() {
- wrapper = new Wrapper('"', '"');
+// wrapper = new Wrapper('"');
}
@Override
diff --git a/hutool-db/src/test/java/cn/hutool/db/DerbyTest.java b/hutool-db/src/test/java/cn/hutool/db/DerbyTest.java
new file mode 100644
index 000000000..19549cb14
--- /dev/null
+++ b/hutool-db/src/test/java/cn/hutool/db/DerbyTest.java
@@ -0,0 +1,50 @@
+package cn.hutool.db;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.sql.SQLException;
+import java.util.List;
+
+/**
+ * Derby数据库单元测试
+ *
+ * @author looly
+ *
+ */
+public class DerbyTest {
+
+ private static final String DS_GROUP_NAME = "derby";
+
+ @BeforeClass
+ public static void init() throws SQLException {
+ Db db = Db.use(DS_GROUP_NAME);
+ try{
+ db.execute("CREATE TABLE test(a INTEGER, b BIGINT)");
+ }catch (SQLException e){
+ // 数据库已存在
+ return;
+ }
+
+ db.insert(Entity.create("test").set("a", 1).set("b", 11));
+ db.insert(Entity.create("test").set("a", 2).set("b", 21));
+ db.insert(Entity.create("test").set("a", 3).set("b", 31));
+ db.insert(Entity.create("test").set("a", 4).set("b", 41));
+ }
+
+ @Test
+ @Ignore
+ public void queryTest() throws SQLException {
+ List query = Db.use(DS_GROUP_NAME).query("select * from test");
+ Assert.assertEquals(4, query.size());
+ }
+
+ @Test
+ @Ignore
+ public void findTest() throws SQLException {
+ List query = Db.use(DS_GROUP_NAME).find(Entity.create("test"));
+ Assert.assertEquals(4, query.size());
+ }
+}
diff --git a/hutool-db/src/test/java/cn/hutool/db/H2Test.java b/hutool-db/src/test/java/cn/hutool/db/H2Test.java
new file mode 100644
index 000000000..86263c783
--- /dev/null
+++ b/hutool-db/src/test/java/cn/hutool/db/H2Test.java
@@ -0,0 +1,42 @@
+package cn.hutool.db;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.SQLException;
+import java.util.List;
+
+/**
+ * H2数据库单元测试
+ *
+ * @author looly
+ *
+ */
+public class H2Test {
+
+ private static final String DS_GROUP_NAME = "h2";
+
+ @BeforeClass
+ public static void init() throws SQLException {
+ Db db = Db.use(DS_GROUP_NAME);
+ db.execute("CREATE TABLE test(a INTEGER, b BIGINT)");
+
+ db.insert(Entity.create("test").set("a", 1).set("b", 11));
+ db.insert(Entity.create("test").set("a", 2).set("b", 21));
+ db.insert(Entity.create("test").set("a", 3).set("b", 31));
+ db.insert(Entity.create("test").set("a", 4).set("b", 41));
+ }
+
+ @Test
+ public void queryTest() throws SQLException {
+ List query = Db.use(DS_GROUP_NAME).query("select * from test");
+ Assert.assertEquals(4, query.size());
+ }
+
+ @Test
+ public void findTest() throws SQLException {
+ List query = Db.use(DS_GROUP_NAME).find(Entity.create("test"));
+ Assert.assertEquals(4, query.size());
+ }
+}
diff --git a/hutool-db/src/test/java/cn/hutool/db/HsqldbTest.java b/hutool-db/src/test/java/cn/hutool/db/HsqldbTest.java
index e5c607c06..54669ce1e 100644
--- a/hutool-db/src/test/java/cn/hutool/db/HsqldbTest.java
+++ b/hutool-db/src/test/java/cn/hutool/db/HsqldbTest.java
@@ -1,15 +1,12 @@
package cn.hutool.db;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
import java.sql.SQLException;
import java.util.List;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import cn.hutool.db.Db;
-import cn.hutool.db.Entity;
-
/**
* HSQLDB数据库单元测试
*
@@ -20,8 +17,8 @@ public class HsqldbTest {
private static final String DS_GROUP_NAME = "hsqldb";
- @Before
- public void init() throws SQLException {
+ @BeforeClass
+ public static void init() throws SQLException {
Db db = Db.use(DS_GROUP_NAME);
db.execute("CREATE TABLE test(a INTEGER, b BIGINT)");
db.insert(Entity.create("test").set("a", 1).set("b", 11));
@@ -35,4 +32,10 @@ public class HsqldbTest {
List query = Db.use(DS_GROUP_NAME).query("select * from test");
Assert.assertEquals(4, query.size());
}
+
+ @Test
+ public void findTest() throws SQLException {
+ List query = Db.use(DS_GROUP_NAME).find(Entity.create("test"));
+ Assert.assertEquals(4, query.size());
+ }
}
diff --git a/hutool-db/src/test/resources/config/db.setting b/hutool-db/src/test/resources/config/db.setting
index 4d764d5a3..b3ef7cc0f 100644
--- a/hutool-db/src/test/resources/config/db.setting
+++ b/hutool-db/src/test/resources/config/db.setting
@@ -28,7 +28,17 @@ url = jdbc:sqlite:test.db
[hsqldb]
url = jdbc:hsqldb:mem:mem_hutool
user = SA
-pass =
+pass =
+
+# 测试用HSQLDB数据库
+[h2]
+url = jdbc:h2:mem:h2_hutool
+user = sa
+pass =
+
+# 测试用HSQLDB数据库
+[derby]
+url = jdbc:derby:.derby/test_db;create=true
# 测试用Oracle数据库
[orcl]