本章主要是增加和查看功能,其他的删除和修改(借出/归还)只是写了工具类和接口
-
DVD类
属性----必须与数据库里面,我们所调用的表一一对应!!!!
package dvd.entry;
/**
* 实体类---一对一参照表
* 表名=类名(首字母大写)
* 字段名===属性名
* 字段类型==属性类型
*/
public class DVD {
private String id;
private String dname;
private Integer state;
private String lendDate;
private Integer lendCount;
public DVD() {
}
public DVD(String id, String dname, Integer state, String lendDate, Integer lendCount) {
this.id = id;
this.dname = dname;
this.state = state;
this.lendDate = lendDate;
this.lendCount = lendCount;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDname() {
return dname;
}
public void setDname(String dname) {
this.dname = dname;
}
public Integer getState() {
return state;
}
public void setState(Integer state) {
this.state = state;
}
public String getLendDate() {
return lendDate;
}
public void setLendDate(String lendDate) {
this.lendDate = lendDate;
}
public Integer getLendCount() {
return lendCount;
}
public void setLendCount(Integer lendCount) {
this.lendCount = lendCount;
}
@Override
public String toString() {
return "DVD{" +
"id='" + id + '\'' +
", dname='" + dname + '\'' +
", state=" + state +
", lendDate='" + lendDate + '\'' +
", lendCount=" + lendCount +
'}';
}
}
-
DBHelper类
主要是提取出来的通用方法。
加载数据库驱动类,获得连接对象
关闭资源
增删改
查询
package dvd.util;
import sun.text.resources.en.FormatData_en_IE;
import triangle.IllegelArgumentException;
import java.lang.reflect.Field;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class DBHelper {
//提取1+2,获得连接对象
public Connection getcon() {
Connection con = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://127.0.0.1:3306/demodvd?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";//localhost也可以写成-----127.0.0.1
标签:String,管理系统,--,DVD,id,dname,state,lendCount,public
From: https://blog.csdn.net/2301_81819439/article/details/143414838