当前位置:网站首页>SQLite使用
SQLite使用
2022-06-30 02:31:00 【菜鸟小窝】
一、概述
SQLite 只需要使用单个db文件即可,不用建立数据库服务。非常简单易用,适用于小型单体项目。
菜鸟教程-SQLite 教程
https://www.runoob.com/sqlite/sqlite-tutorial.html
二、使用
使用Navicat可以直接新建SQLite数据库。
三、集成 SpringBoot
1、项目案例
(1)application.yml
spring:
datasource:
driver-class-name: org.sqlite.JDBC
# 路径:db/mydb.bd
#url: jdbc:sqlite:db/mydb.db
# 路径:src/main/resources/db/mydb.db
#url: jdbc:sqlite::resource:db/mydb.db
url: jdbc:sqlite:D:/Program Files/sqlite3/mydb.db
username:
password:
mybatis:
mapper-locations:
- classpath:mapper/*.xml
(2)pom.xml
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.36.0.3</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
(3)student.xml
src/main/resources/mapper/student.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="student">
<resultMap id="BaseResultMap" type="java.util.HashMap"></resultMap>
<parameterMap id="BaseParameterMap" type="java.util.HashMap"></parameterMap>
<select id="findStudent" resultMap="BaseResultMap" parameterMap="BaseParameterMap">
select
"id",
"name"
from
student
where
id = #{id}
</select>
</mapper>
(4)测试代码
src/test/java/com/scy/sqlite/SqliteApplicationTests.java
package com.scy.sqlite;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SpringBootTest
class SqliteApplicationTests {
@Resource
SqlSession sqlSession;
@Test
void contextLoads() {
Map map = new HashMap();
map.put("id", "2");
List<Object> studentList = sqlSession.selectList("student.findStudent", map);
System.out.println(studentList);
}
}
边栏推荐
- Day_ 19 multithreading Basics
- Pytorch学习(二)
- DHU programming exercise
- Jupyter notebook显示k线图集合
- SiteLock九个常见问题
- Linear algebra Chapter 3 summary of vector and vector space knowledge points (Jeff's self perception)
- What is digicert smart seal?
- Matlab code running tutorial (how to run the downloaded code)
- DDoS attacks and destructive ripple effects against online gamers
- 2.8 【 weight of complete binary tree 】
猜你喜欢

What files does a CA digital certificate contain? How to view SSL certificate information?

NPDP产品经理国际认证考试报名有什么要求?

Weekly recommended short video: why is the theory correct but can not get the expected results?

How vscode debugs into standard library files / third-party package source code

2.8 【 weight of complete binary tree 】
![[on] [DSTG] dynamic spatiotemporalgraph revolutionary neural networks for traffic data impact](/img/c3/f9d6399c931a006ca295bb1e3ac427.png)
[on] [DSTG] dynamic spatiotemporalgraph revolutionary neural networks for traffic data impact

Linear algebra Chapter 4 Summary of knowledge points of linear equations (Jeff's self perception)

Merge sort

DigiCert Smart Seal是什么?

SSL证书七大常见错误及解决方法
随机推荐
How difficult is the PMP Exam under the new syllabus? Comprehensive analysis
1380. lucky numbers in matrices
Global and Chinese markets of liquid optical waveguides 2022-2028: Research Report on technology, participants, trends, market size and share
主流CA吊销俄罗斯数字证书启示:升级国密算法SSL证书,助力我国网络安全自主可控
新考纲下的PMP考试有多难?全面解析
速看 2021-2022年23项重大网络犯罪统计数据
C语言 pivot_root的Invalid argument错误解决方案
Le Code autojs peut - il être chiffré? Oui, présentation des techniques de chiffrement autojs
FDA邮件安全解决方案
NPDP产品经理国际认证考试报名有什么要求?
DigiCert Smart Seal是什么?
桶排序
Jupyter notebook显示k线图集合
Can autojs code be encrypted? Yes, display of autojs encryption skills
Summary of knowledge points about eigenvalues and eigenvectors of matrices in Chapter 5 of Linear Algebra (Jeff's self perception)
Matlab code running tutorial (how to run the downloaded code)
JS advanced -h5 new features
DHU programming exercise
DDoS attacks and destructive ripple effects against online gamers
Alphassl digital certificate