Skip to content

Instantly share code, notes, and snippets.

@tandat2209
Created April 7, 2016 08:37
Show Gist options
  • Save tandat2209/3cbed310cc76cbb20ba975974abbbd9b to your computer and use it in GitHub Desktop.
Save tandat2209/3cbed310cc76cbb20ba975974abbbd9b to your computer and use it in GitHub Desktop.
QuanLyTrungTamMoiGIoiBatDongSan
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package model.bean;
/**
*
* @author dracu
*/
public class NhanVien {
private String maNV;
private String tenNV;
private String matKhau;
private String ngaySinh;
private String gioiTinh;
private String chucVu;
private String diaChi;
private String soDienThoai;
private String email;
private boolean admin;
public String getMaNV() {
return maNV;
}
public void setMaNV(String maNV) {
this.maNV = maNV;
}
public String getTenNV() {
return tenNV;
}
public void setTenNV(String tenNV) {
this.tenNV = tenNV;
}
public String getMatKhau() {
return matKhau;
}
public void setMatKhau(String matKhau) {
this.matKhau = matKhau;
}
public String getNgaySinh() {
return ngaySinh;
}
public void setNgaySinh(String ngaySinh) {
this.ngaySinh = ngaySinh;
}
public String getGioiTinh() {
return gioiTinh;
}
public void setGioiTinh(String gioiTinh) {
this.gioiTinh = gioiTinh;
}
public String getChucVu() {
return chucVu;
}
public void setChucVu(String chucVu) {
this.chucVu = chucVu;
}
public String getDiaChi() {
return diaChi;
}
public void setDiaChi(String diaChi) {
this.diaChi = diaChi;
}
public String getSoDienThoai() {
return soDienThoai;
}
public void setSoDienThoai(String soDienThoai) {
this.soDienThoai = soDienThoai;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public boolean isAdmin() {
return admin;
}
public void setAdmin(boolean admin) {
this.admin = admin;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package model.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author dracu
*/
public class Database {
private Connection conn;
private String db = "trungtambds";
private String user = "root";
private String password = "";
private String url = "jdbc:mysql://localhost:3306/"+ db +"?useUnicode=true&characterEncoding=UTF-8";
public Connection getConnection(){
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url, user, password);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
return conn;
}
public void closeConnection() {
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
Database db = new Database();
Connection conn = db.getConnection();
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package model.dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.bean.NhanVien;
/**
*
* @author dracu
*/
public class NhanVienDAO {
Database db = new Database();
Connection conn;
public NhanVien getNhanVienByMaNV(String maNV){
String query = "select * from nhanvien where maNV="+maNV;
NhanVien nv = new NhanVien();
try {
Statement st = db.getConnection().createStatement();
ResultSet rs = st.executeQuery(query);
if(rs.next()){
nv.setMaNV(rs.getString("MaNV"));
nv.setTenNV(rs.getString("TenNV"));
nv.setMatKhau(rs.getString("MatKhau"));
nv.setNgaySinh(rs.getString("NgaySinh"));
nv.setGioiTinh(rs.getString("GioiTinh"));
nv.setChucVu(rs.getString("ChucVu"));
nv.setDiaChi(rs.getString("DiaChi"));
nv.setSoDienThoai(rs.getString("SoDienThoai"));
nv.setEmail(rs.getString("Email"));
}
return nv;
} catch (SQLException ex) {
Logger.getLogger(NhanVienDAO.class.getName()).log(Level.SEVERE, null, ex);
} finally{
db.closeConnection();
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment