当前位置:网站首页>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);
}
}
边栏推荐
- DDoS attacks and destructive ripple effects against online gamers
- A quick look at the statistical data of 23 major cyber crimes from 2021 to 2022
- DigiCert Smart Seal是什么?
- What are the requirements for NPDP product manager international certification examination?
- Linear algebra Chapter 3 summary of vector and vector space knowledge points (Jeff's self perception)
- Network neuroscience -- a review of network Neuroscience
- dhu编程练习
- Shell Sort
- JS advanced -es6 syntax
- Global and Chinese market of relay lens 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

有流量,但没有销售?增加网站销量的 6 个步骤

打造创客教育中精湛技艺

AutoJS代碼能加密嗎?YES,AutoJS加密技巧展示

Bubble sort

FDA mail security solution

What is digicert smart seal?

Five cheapest wildcard SSL certificate brands

Quick sort

FDA ESG regulation: digital certificate must be used to ensure communication security

学术汇报(academic presentation)/PPT应该怎么做?
随机推荐
A quick look at the statistical data of 23 major cyber crimes from 2021 to 2022
dhu编程练习
打造創客教育中精湛技藝
How long is the general term of the bank's financial products?
Jupyter notebook displays a collection of K-line graphs
[dry goods sharing] the latest WHQL logo certification application process
论文回顾:Playful Palette: An Interactive Parametric Color Mixer for Artists
Recursion frog jumping steps problem
SiteLock九个常见问题
DDoS attacks and destructive ripple effects against online gamers
dhu编程练习
What is digicert smart seal?
Shell Sort
Quick sort
Traffic, but no sales? 6 steps to increase website sales
Four, forty, fourhundred swatches
Global and Chinese market of subscription revenue management software 2022-2028: Research Report on technology, participants, trends, market size and share
Jupyter notebook显示k线图集合
dhu编程练习
Unity3D UGUI强制刷新Layout(布局)组件