栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SQLite使用

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SQLite使用

一、概述

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
        
            org.xerial
            sqlite-jdbc
            3.36.0.3
        

        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.2.2
        
(3)student.xml

src/main/resources/mapper/student.xml




	
	

	
		select
			"id",
			"name"
		from
			student
		where
			id = #{id}
	


(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 studentList = sqlSession.selectList("student.findStudent", map);
        System.out.println(studentList);
    }

}


转载请注明:文章转载自 www.mshxw.com
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号