在JSTL 中使用小型数据库 SQLite

在JSTL 中使用小型数据库 SQLite

一、Sqlite 数据库命令行工具的下载

下载地址:
https://www.sqlite.org/2021/sqlite-tools-win32-x86-3360000.zip
解压缩后 3 个文件
sqldiff.exe 数据库比较工具
sqlite3.exe 数据库命令行交互工具
sqlite3_analyzer.exe 数据库分析器

二、Sqlite 数据库 shell 工具的使用方法

1.创建数据库
Sqlite 数据库命令行的启动与帮助信息的获取
用 DOS 进入解压缩后的文件夹,并运行命令 sqlite3.exe,进入其命令行 shell.
sqltie>.help
在这里插入图片描述

利用 Sqlite 数据库命令行创建数据库
sqlite>.open TestDB /打开并创建一个名为 TestDB 的数据库文件,若没有此文件就创建/
在这里插入图片描述
2.Sqlite 数据库中表的创建:

sqlite>CREATE TABLE websites (
id int Not Null Primary Key,
name varchar(20) Not Null,
url varchar(255) Not Null,
alexa int(11) Not Null,
country char(20) Not Null
);

3.表中数据的插入

sqlite>INSERT INTO websites VALUES
('1', 'Google', 'https://www.google.cm/', '1', 'USA'),
('2', '淘宝', 'https://www.taobao.com/', '13', 'CN'),
('3', '菜鸟教程', 'http://www.runoob.com', '5892', ''),
('4', '微博', 'http://weibo.com/', '20', 'CN'),
('5', 'Facebook', 'https://www.facebook.com/', '3', 'USA');

在这里插入图片描述
4.Sqlite 数据库命令行的退出
sqlite>.quit.

三、ER图转化为数据库

在这里插入图片描述
3.1建表

sqlite> .open exp8.db
sqlite> create table Studs(
   ...> id int not null primary key,
   ...> name varchar(20) not null
   ...> );
sqlite> select *from Studs
   ...> ;
sqlite> create table Teachers(
   ...> id int not null primary key,
   ...> name varchar(20) not null
   ...> );
sqlite> create table Courses(
   ...> id int not null primary key,
   ...> name varchar(20) not null
   ...> );
sqlite> create table selectCourses(
   ...> id integer primary key autoincrement,
   ...> curdate date default now,
   ...> stid char(8),
   ...> coid char(8),
   ...> constraint fk_1 foreign Key(stid) references Studs(id),
   ...> constraint fk_2 foreign Key(coid) references Coursee(id)
   ...> );
sqlite> create table teachings(
   ...>  id integer primary key autoincrement,
   ...> curdate date default now,
   ...> coid char(8),
   ...> teid char(8),
   ...> constraint fk_1 foreign Key(coid) references Courses(id),
   ...> constraint fk_2 foreign Key(teid) references Teachers(id)
   ...> );

注意:在学生表和课程表之间的“业务表”。必须包含三个属性:
1.业务发生的时间。
2.是谁进行的该业务的操作。
3.业务发生的唯一Id

3.2 向表中插入数据

sqlite> insert into Studs values
   ...> ('2012151','王明'),
   ...> ('2012152','张旭'),
   ...> ('2012153','刘琦');
sqlite> select * from Studs
   ...> ;
2012151|王明
2012152|张旭
2012153|刘琦
sqlite> insert into Courses values
   ...> ('1','JavaEE'),
   ...> ('2','数据库'),
   ...> ('3','C语言');
sqlite> insert into Teachers values
   ...> ('1','王玉'),
   ...> ('2','张宇'),
   ...> ('3','刘洋');

3.3 输出数据库中相应的表

drop table +表名

觉得对自己的看完有收获的。麻烦点个赞呗。创作不易呀。在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_48164590/article/details/121251547