sex
varchar(5) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘姓别: 男, 女’,
source
varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘学生来源: 老学员推荐,知乎,社招’,
PRIMARY KEY (id
) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
– Records of student
INSERT INTO student
VALUES (2, ‘张小二’, ‘1002’, ‘男’, ‘老学员推荐’);
INSERT INTO student
VALUES (3, ‘张小三’, ‘1003’, ‘男’, ‘知乎’);
INSERT INTO student
VALUES (4, ‘张小四’, ‘1004’, ‘女’, ‘社招’);
INSERT INTO student
VALUES (5, ‘张小五’, ‘1005’, ‘女’, ‘社招’);
INSERT INTO student
VALUES (7, ‘靓仔一号·’, ‘14250’, ‘男’, ‘靓仔学院’);
SET FOREIGN_KEY_CHECKS = 1;
dao类,
StuDao.class
package com.dao;
import com.db.Dbclose;
import com.db.Dbconn;
import com.entity.Student;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/**
-
对数据库的操作
-
@author 北落燕门
-
@date 2021.05.11
*/
public class StuDao {
//初始化配置
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
/**
- @显示所有学生数据
*/
public ArrayList showStuList() {
ArrayList stuList = new ArrayList();
conn = Dbconn.getconn();
String sql = “SELECT * FROM student”;
try {
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
int id = rs.getInt(1);
String name = rs.getString(2);
String sn = rs.getString(3);
String sex = rs.getString(4);
String source = rs.getString(5);
Student student = new Student(id, name, sn, sex, source);
stuList.add(student);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
Dbclose.getclose(conn, pstmt, rs);
}
return stuList;
}
/**
- @添加学生
*/
public boolean addStu(Student stu)