1.创建user表
CREATE table user(
id int PRIMARY key auto_increment COMMENT'用户ID',
username VARCHAR(55) COMMENT'用户名',
password VARCHAR(55) COMMENT'密码'
);
insert into user values(1,'zs','12345');
insert into user values(2,'ls','123456');
2.创建实体类(pojo包)
//实体类
public class User {
private int id;
private String username;
private String password;
public User(){
}
public User(int id, String username, String password) {
this.id = id;
this.username = username;
this.password = password;
}
public User(String username, String password) {
this.username = username;
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}
3、工具类(util包)
//工具类
public class JDBC_Util {
//创建Connection对象
public static Connection conn(){
Connection connection = null;
try {
//加载驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//获得connection连接
String url = "jdbc:mysql://localhost:3306/bjsxt