You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
166 lines
4.4 KiB
166 lines
4.4 KiB
|
|
package dao.impl;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.Statement;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import dao.GuanliyuanDao;
|
|
import entity.Guanliyuan;
|
|
|
|
public class GuanliyuanImpl implements GuanliyuanDao{
|
|
|
|
public Guanliyuan findById(String id) {
|
|
Guanliyuan acyc=new Guanliyuan();
|
|
try {
|
|
|
|
Connection conn = JDBCUtil.getConnection();
|
|
String sql = "select*from guanliyuan where id = ?";
|
|
PreparedStatement prestm=conn.prepareStatement(sql);
|
|
prestm.setInt(1, Integer.valueOf(id));
|
|
ResultSet rs=prestm.executeQuery();
|
|
|
|
while(rs.next()) {
|
|
Guanliyuan guanliyuan=new Guanliyuan();
|
|
guanliyuan.setId(rs.getInt("id"));
|
|
guanliyuan.setYonghumingyc(rs.getString("yonghumingyc"));
|
|
guanliyuan.setMimayc(rs.getString("mimayc"));
|
|
guanliyuan.setJiaoseyc(rs.getString("jiaoseyc"));
|
|
acyc=guanliyuan;
|
|
}
|
|
rs.close();
|
|
prestm.close();
|
|
conn.close();
|
|
}
|
|
catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return acyc;
|
|
}
|
|
|
|
|
|
@Override
|
|
public List<Guanliyuan> findAll() {
|
|
ArrayList<Guanliyuan> zhushus=new ArrayList<Guanliyuan>();
|
|
try {
|
|
Connection conn = JDBCUtil.getConnection();
|
|
|
|
String sqlyc ="select *from guanliyuan";
|
|
Statement stsyc =conn.createStatement();
|
|
ResultSet rsyc=stsyc.executeQuery(sqlyc);
|
|
|
|
while(rsyc.next()) {
|
|
Guanliyuan guanliyuan=new Guanliyuan();
|
|
guanliyuan.setId(rsyc.getInt("id"));
|
|
guanliyuan.setYonghumingyc(rsyc.getString("yonghumingyc"));
|
|
guanliyuan.setMimayc(rsyc.getString("mimayc"));
|
|
guanliyuan.setJiaoseyc(rsyc.getString("jiaoseyc"));
|
|
zhushus.add(guanliyuan);
|
|
}
|
|
rsyc.close();
|
|
stsyc.close();
|
|
conn.close();
|
|
}
|
|
catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
// TODO 自动生成的方法存根
|
|
return zhushus;
|
|
}
|
|
|
|
|
|
@Override
|
|
public int modify(Guanliyuan guanliyuan) {
|
|
try {
|
|
Connection conn = JDBCUtil.getConnection();
|
|
|
|
String sqlyc ="update guanliyuan set yonghumingyc=?,mimayc=?,jiaoseyc=? where id=?";
|
|
PreparedStatement prestmyc=conn.prepareStatement(sqlyc);
|
|
prestmyc.setString(1,guanliyuan.getYonghumingyc());
|
|
prestmyc.setString(2,guanliyuan.getMimayc());
|
|
prestmyc.setString(3,guanliyuan.getJiaoseyc());
|
|
prestmyc.setInt(4,guanliyuan.getId());
|
|
prestmyc.executeUpdate();
|
|
prestmyc.close();
|
|
conn.close();
|
|
}
|
|
catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
@Override
|
|
public int create(Guanliyuan guanliyuan) {
|
|
try {
|
|
Connection conn = JDBCUtil.getConnection();
|
|
String sqlyc ="Insert into guanliyuan (yonghumingyc,mimayc,jiaoseyc) values(?,?,?)";
|
|
PreparedStatement prestmyc=conn.prepareStatement(sqlyc);
|
|
prestmyc.setString(1,guanliyuan.getYonghumingyc());
|
|
prestmyc.setString(2,guanliyuan.getMimayc());
|
|
prestmyc.setString(3,guanliyuan.getJiaoseyc());
|
|
prestmyc.executeUpdate();
|
|
prestmyc.close();
|
|
conn.close();
|
|
}
|
|
catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
@Override
|
|
public int remove(Guanliyuan guanliyuan) {
|
|
int flagyc=0;
|
|
try {
|
|
Connection conn = JDBCUtil.getConnection();
|
|
String sqlyc ="delete from guanliyuan where id=?";
|
|
PreparedStatement prestmyc=conn.prepareStatement(sqlyc);
|
|
prestmyc.setInt(1, guanliyuan.getId());
|
|
flagyc = prestmyc.executeUpdate();
|
|
prestmyc.close();
|
|
conn.close();
|
|
}
|
|
catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return flagyc;
|
|
}
|
|
|
|
|
|
@Override
|
|
public Guanliyuan findByUsername(String yonghuming) {
|
|
Guanliyuan acyc=new Guanliyuan();
|
|
try {
|
|
|
|
Connection conn = JDBCUtil.getConnection();
|
|
String sql = "select*from guanliyuan where yonghumingyc = ?";
|
|
PreparedStatement prestm=conn.prepareStatement(sql);
|
|
prestm.setString(1, yonghuming);
|
|
ResultSet rs=prestm.executeQuery();
|
|
|
|
while(rs.next()) {
|
|
Guanliyuan guanliyuan=new Guanliyuan();
|
|
guanliyuan.setId(rs.getInt("id"));
|
|
guanliyuan.setYonghumingyc(rs.getString("yonghumingyc"));
|
|
guanliyuan.setMimayc(rs.getString("mimayc"));
|
|
guanliyuan.setJiaoseyc(rs.getString("jiaoseyc"));
|
|
acyc=guanliyuan;
|
|
}
|
|
rs.close();
|
|
prestm.close();
|
|
conn.close();
|
|
}
|
|
catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return acyc;
|
|
}
|
|
|
|
}
|