在JSTL 中使用小型数据库 SQLite

文章目录

*

+ 一、Sqlite 数据库命令行工具的下载
+
* 下载地址:
+ 二、Sqlite 数据库 shell 工具的使用方法
+
* 1.创建数据库
* 2.Sqlite 数据库中表的创建:
* 3.表中数据的插入
* 4.Sqlite 数据库命令行的退出
+ 三、ER图转化为数据库
+
* 3.1建表
* 3.2 向表中插入数据
* 3.3 输出数据库中相应的表
+ 四、总结

一、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

在JSTL 中使用小型数据库 SQLite

利用 Sqlite 数据库命令行创建数据库
sqlite>.open TestDB / 打开并创建一个名为 TestDB 的数据库文件,若没有此文件就创建/

在JSTL 中使用小型数据库 SQLite
; 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');

在JSTL 中使用小型数据库 SQLite
4.Sqlite 数据库命令行的退出

sqlite>.quit.

三、ER图转化为数据库

在JSTL 中使用小型数据库 SQLite
; 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 +表名

四、总结

在JSTL 中使用小型数据库 SQLite

Original: https://blog.csdn.net/qq_48164590/article/details/121251547
Author: code袁
Title: 在JSTL 中使用小型数据库 SQLite

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/816227/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球