数据库信息:
一、创建一个bean包 里面创建一个实体类
Goods类:
package com.nai.bean;
public class Goods {
private Integer gid;
private String gname;
private Double price;
private String mark;
public Goods(Integer gid, String gname, Double price, String mark) {
this.gid = gid;
this.gname = gname;
this.price = price;
this.mark = mark;
}
public Goods() {
}
public Integer getGid() {
return gid;
}
@Override
public String toString() {
return "Goods{" +
"gid=" + gid +
", gname='" + gname + '\'' +
", price='" + price + '\'' +
", mark='" + mark + '\'' +
'}';
}
public void setGid(Integer gid) {
this.gid = gid;
}
public String getGname() {
return gname;
}
public void setGname(String gname) {
this.gname = gname;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getMark() {
return mark;
}
public void setMark(String mark) {
this.mark = mark;
}
}
第二步:创建一个Dao包 里面创建一个GoodsDaoImpl类
GoodsDaoImpl类:
package com.nai.Dao.impl;
import com.nai.bean.Goods;
import com.nai.bean.User;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class GoodsDaoImpl {
private static String jdbcdirver = "com.mysql.cj.jdbc.Driver";
private static String jdbcurl = "jdbc:mysql://localhost:3306/myweb?useSSL=false&serverTimezone=UTC";
private static String jdbcuser = "root";
private static String jdbcpassword = "root";
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
User Fi = null;
int row = 0;
public L