新增JdbcTemplate操作sqlite的测试代码

This commit is contained in:
aoshiguchen
2022-07-08 11:59:42 +08:00
parent 09e66b5367
commit 10c7a982dc
4 changed files with 80 additions and 1 deletions
+6
View File
@@ -33,6 +33,12 @@
<version>8.0.29</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
Binary file not shown.
@@ -38,7 +38,7 @@ import java.util.Map;
* @author: aoshiguchen
* @date: 2022/6/27
*/
public class JdbcTemplateTest {
public class JdbcTemplateTestForMySql {
private JdbcTemplate jdbcTemplate;
{
@@ -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, "[email protected]", "", 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;
}
}