From 10c7a982dca2ecbe039f0172babf8209705b7364 Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Fri, 8 Jul 2022 11:59:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EJdbcTemplate=E6=93=8D?= =?UTF-8?q?=E4=BD=9Csqlite=E7=9A=84=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- neutrino-core/pom.xml | 6 ++ neutrino-core/sqlite.db | Bin 0 -> 20480 bytes ...est.java => JdbcTemplateTestForMySql.java} | 2 +- .../template/JdbcTemplateTestForSqlite.java | 73 ++++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 neutrino-core/sqlite.db rename neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/{JdbcTemplateTest.java => JdbcTemplateTestForMySql.java} (99%) create mode 100644 neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTestForSqlite.java 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 0000000000000000000000000000000000000000..c67e431caf0eef2f644c065ba3617f7ec083f2ac GIT binary patch literal 20480 zcmeI&J#W)M7zgmXIqM5Jj5?vTkc$&p%e65=>j#YUBd zoe#jb03>E+BnAdn5Mo7Q=WLOvP1A%f$e{lzj?Z^~?oL0yNGIQ;hjqv2?8(sU+djKP zZW2mKnK430T5NH#&5|rKvDtyx({uT&vT3qcY-Z#w65HA)+ix=`H*Sjz5(FRs0SG_< z0uX=z1R^1Dwwp?36@^X}-+t`!$(Vb=7Qf%BR?I3hEBESErUpeS%WX2II$f1H1E2S} z#~OzwYaG?k&3L64^q5wnM=2$Q83#Ys^OzKIrg;L+JwDLS-&^9*ZI}FWx{u zBk>mc8-qxs5@9zP@lWMXMEsB-009U<00Izz00bZa0SG_<0ucDO1a8q3*`O0%J(0i5AH)s`0uX=z1Rwwb2tWV= z5P$##AOL~L3Z&waA_q%Gv}{Z=(#savD3YWtslfOD$X-+o3<3~<00bZa0SG_<0uX=z q1R$_Z;9B4RvHpJ@C+Z;p0SG_<0uX=z1Rwwb2tWV=krepj`Ts9I(RrEx literal 0 HcmV?d00001 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; + } + +} +