Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

创建数据库

对于数据库的知识如果有遗漏,可以查看这篇博客mysql常用命令_artly1的博客-CSDN博客

sql代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
-- 创建demo数据库
CREATE DATABASE demo;

-- 使用demo数据库
USE demo;

-- 创建student表(使用你之前提供的结构)
CREATE TABLE student (
id bigint(20) NOT NULL AUTO_INCREMENT,
number varchar(255) NOT NULL,
name varchar(255) NOT NULL,
age int(11) NOT NULL,
chi int(11) NOT NULL,
math int(11) NOT NULL,
eng int(11) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=138 DEFAULT CHARSET=utf8;

-- 创建user表
CREATE TABLE user (
id bigint(20) NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

-- 插入学生数据
INSERT INTO student (number, name, age, chi, math, eng) VALUES
(1,'101','张三',18,99,99,99),
(2,'102','李四',19,92,80,55),
(3,'103','王五',20,88,79,88),
(4,'104','马六',21,75,88,99),
(5,'105','赵七',17,88,54,67),
(6,'106','陈八',24,87,77,33),
(7,'107','朱九',23,91,44,56),
(8,'108','小红',8,82,77,90),
(9,'109','小强',8,78,67,88),
(10,'110','大白',17,73,72,71),
(11,'111','小花',20,73,73,88),
(12,'112','小新',7,59,59,59),
(13,'113','小黄',14,78,99,93);

-- 插入用户数据
INSERT INTO user (username, password) VALUES
('abc', '123'),
('111', '123');

连接数据库

代码

1
2
3
4
5
datasource:
username: root
password: '123456'
url: jdbc:mysql://127.0.0.1:3306/demo?characterEncoding=UTF-8&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver

username: 数据库用户名

password: ‘数据库密码’

url: jdbc:mysql://127.0.0.1:3306/数据库名?characterEncoding=UTF-8&serverTimezone=UTC

评论