MySQL代码如下:
CREATE DATABASE text;
CREATE TABLE employee_info(
stuName VARCHAR(32) ,
stuSex varchar(4) ,
stuAge INT ,
position VARCHAR(32)
);
INSERT INTO employee_info (stuName,stuSex,stuAge,position) VALUES ('张三','男',45,'技术总监');
INSERT INTO employee_info (stuName,stuSex,stuAge,position) VALUES ('李四','男',35,'总经理');
INSERT INTO employee_info (stuName,stuSex,stuAge,position) VALUES ('王五','男',26,'会计');
INSERT INTO employee_info (stuName,stuSex,stuAge,position) VALUES ('赵六','男',34,'人事经理');
Java代码如下:
先在IDEA中创建实体类,使用快捷键ait+insret自动构造代码
public class Student {
//属性
private String stuName;
private String stuSex;
private int stuAge;
private String position;
}
JDBC连接数据库,需要配置四大参数,同时需要导入数据库对应的驱动包参数如下: