diff --git a/neutrino-core/pom.xml b/neutrino-core/pom.xml index 52f916d6..4e90bbaa 100644 --- a/neutrino-core/pom.xml +++ b/neutrino-core/pom.xml @@ -33,6 +33,12 @@ 8.0.29 test + + org.xerial + sqlite-jdbc + 3.7.2 + test + org.apache.velocity velocity-engine-core diff --git a/neutrino-core/sqlite.db b/neutrino-core/sqlite.db new file mode 100644 index 00000000..c67e431c Binary files /dev/null and b/neutrino-core/sqlite.db differ diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTest.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTestForMySql.java similarity index 99% rename from neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTest.java rename to neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTestForMySql.java index 314a93ed..155f797f 100644 --- a/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTest.java +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTestForMySql.java @@ -38,7 +38,7 @@ import java.util.Map; * @author: aoshiguchen * @date: 2022/6/27 */ -public class JdbcTemplateTest { +public class JdbcTemplateTestForMySql { private JdbcTemplate jdbcTemplate; { diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTestForSqlite.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTestForSqlite.java new file mode 100644 index 00000000..4af1102e --- /dev/null +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTestForSqlite.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.template; + +import com.alibaba.druid.pool.DruidDataSource; +import fun.asgc.neutrino.core.db.annotation.Id; +import lombok.Data; +import lombok.experimental.Accessors; +import org.junit.Test; + +import java.sql.SQLException; +import java.util.Date; + +/** + * + * @author: aoshiguchen + * @date: 2022/7/8 + */ +public class JdbcTemplateTestForSqlite { + private JdbcTemplate jdbcTemplate; + + { + DruidDataSource dataSource = new DruidDataSource(); + dataSource.setUrl("jdbc:sqlite:sqlite.db"); + dataSource.setDriverClassName("org.sqlite.JDBC"); + jdbcTemplate = new JdbcTemplate(dataSource); + } + + @Test + public void 新增数据1() throws SQLException { + jdbcTemplate.update("insert into user(`id`,`name`,`age`,`email`,`sex`,`create_time`) values(?,?,?,?,?,?)", 1, "张三", 21, "zhangsan@qq.com", "男", new Date()); + } + + @Test + public void 查询单个行记录2() throws SQLException { + User user = jdbcTemplate.query(User.class, "select * from user where id = 1"); + System.out.println(user); + } + + @Accessors(chain = true) + @Data + public static class User { + @Id + private Long id; + private String name; + private Integer age; + private String email; + private String sex; + private Date createTime; + private Date updateTime; + } + +} +