Bản quyền thuộc về TITV.vn,
vui lòng không đăng tải lại nội dung từ trang này.
Video giải thích chi tiết
Nội dung chi tiết
package database;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.mysql.cj.jdbc.Driver;
public class JDBCUtil {
public static Connection getConnection() {
Connection c = null;
try {
// Đăng ký MySQL Driver với DriverManager
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
// Các thông số
String url = "jdbc:mySQL://localhost:3306/nhasach";
String username = "root";
String password = "";
// Tạo kết nối
c = DriverManager.getConnection(url, username, password);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return c;
}
public static void closeConnection(Connection c) {
try {
if(c!=null) {
c.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void printInfo(Connection c) {
try {
if(c!=null) {
DatabaseMetaData mtdt = c.getMetaData();
System.out.println(mtdt.getDatabaseProductName());
System.out.println(mtdt.getDatabaseProductVersion());
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
package model;
public class Sach {
private String id;
private String tenSach;
private float giaBan;
private int namXuatBan;
public Sach() {
super();
}
public Sach(String id, String tenSach, float giaBan, int namXuatBan) {
super();
this.id = id;
this.tenSach = tenSach;
this.giaBan = giaBan;
this.namXuatBan = namXuatBan;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTenSach() {
return tenSach;
}
public void setTenSach(String tenSach) {
this.tenSach = tenSach;
}
public float getGiaBan() {
return giaBan;
}
public void setGiaBan(float giaBan) {
this.giaBan = giaBan;
}
public int getNamXuatBan() {
return namXuatBan;
}
public void setNamXuatBan(int namXuatBan) {
this.namXuatBan = namXuatBan;
}
}
package model;
import java.sql.Date;
public class KhachHang {
private int id;
private String hoVaTen;
private Date ngaySinh;
private String diaChi;
public KhachHang() {
super();
}
public KhachHang(int id, String hoVaTen, Date ngaySinh, String diaChi) {
super();
this.id = id;
this.hoVaTen = hoVaTen;
this.ngaySinh = ngaySinh;
this.diaChi = diaChi;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getHoVaTen() {
return hoVaTen;
}
public void setHoVaTen(String hoVaTen) {
this.hoVaTen = hoVaTen;
}
public Date getNgaySinh() {
return ngaySinh;
}
public void setNgaySinh(Date ngaySinh) {
this.ngaySinh = ngaySinh;
}
public String getDiaChi() {
return diaChi;
}
public void setDiaChi(String diaChi) {
this.diaChi = diaChi;
}
}
package dao;
import java.util.ArrayList;
public interface DAOInterface<T> {
public int insert(T t);
public int update(T t);
public int delete(T t);
public ArrayList<T> selectAll();
public T selectById(T t);
public ArrayList<T> selectByCondition(String condition);
}
package dao;
import java.util.ArrayList;
import model.Sach;
public class SachDAO implements DAOInterface<Sach>{
public static SachDAO getInstance() {
return new SachDAO();
}
@Override
public int insert(Sach t) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int update(Sach t) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int delete(Sach t) {
// TODO Auto-generated method stub
return 0;
}
@Override
public ArrayList<Sach> selectAll() {
// TODO Auto-generated method stub
return null;
}
@Override
public Sach selectById(Sach t) {
// TODO Auto-generated method stub
return null;
}
@Override
public ArrayList<Sach> selectByCondition(String condition) {
// TODO Auto-generated method stub
return null;
}
}
package dao;
import java.util.ArrayList;
import model.KhachHang;
public class KhachHangDAO implements DAOInterface<KhachHang>{
public static KhachHangDAO getInstance() {
return new KhachHangDAO();
}
@Override
public int insert(KhachHang t) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int update(KhachHang t) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int delete(KhachHang t) {
// TODO Auto-generated method stub
return 0;
}
@Override
public ArrayList<KhachHang> selectAll() {
// TODO Auto-generated method stub
return null;
}
@Override
public KhachHang selectById(KhachHang t) {
// TODO Auto-generated method stub
return null;
}
@Override
public ArrayList<KhachHang> selectByCondition(String condition) {
// TODO Auto-generated method stub
return null;
}
}
Không có nhận xét nào:
Đăng nhận xét