用户管理系统
数据库表结构
用户实体类
//实体类,映射数据库的字段
public class User {
//1.对属性的封装
private int id;//用户id
private String username;//用户名
private String password;//用户密码
//2.get and set
public int getId() {
return id;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public void setId(int id) {
this.id = id;
}
public void setUsername(String usename) {
this.username = usename;
}
public void setPassword(String password) {
this.password = password;
}
//3.构造方法
public User(int id, String username, String password) {
this.id = id;
this.username = username;
this.password = password;
}
public User() {
}
public User(String username, String password) {
this.username = username;
this.password = password;
}
//4.toString方法的重写
@Override
public String toString() {
return "User{" +
"id=" + id +
", usename='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}
数据库连接
import java.sql.*;
public class DBUtil {
private static String driver="com.mysql.jdbc.Driver";
private static String url="jdbc:mysql://localhost:3306/java7?useSSL=true&characterEncoding=utf-8";
private static String user="root";
private static String password="123";
//1.获取驱动
static {
try {
Class.forName(driver);
} catch (Exception e) {
e.printStackTrace();
}
}
//2.创建连接
public static Connection get_conn()throws SQLException
{
Connection conn &