package com.zhuce.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.zhuce.entity.Admin;
import com.zhuce.entity.Msg;
/**
* @author weixin:zfldiv1101
*/
public class AdminDao {
public List<Msg> getAllMsg(String schoolname, String zhuanyename) {
List<Msg> list = new ArrayList<Msg>();
Connection conn = DbHelper.getConnection();
String sql = "select * from msg where 1=1 ";
if (schoolname != null && !"".equals(schoolname)) {
sql += " and schoolname like '%"+schoolname+"%'";
}
if(zhuanyename != null && !"".equals(zhuanyename)) {
sql += " and zhuanyename like '%"+zhuanyename+"%'";
}
try {
PreparedStatement pst = conn.prepareStatement(sql);
ResultSet rst = pst.executeQuery();
while (rst.next()) {
Msg admin = new Msg();
admin.setId(rst.getInt("id"));
admin.setSchoolname(rst.getString("schoolname"));
admin.setZhuanyename(rst.getString("zhuanyename"));
list.add(admin);
}
rst.close();
pst.close();
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public List<Admin> getAllAdmin() {
List<Admin> list = new ArrayList<Admin>();
Connection conn = DbHelper.getConnection();
String sql = "select * from admina ";
try {
PreparedStatement pst = conn.prepareStatement(sql);
ResultSet rst = pst.executeQuery();
while (rst.next()) {
Admin admin = new Admin();
admin.setId(rst.getInt("id"));
admin.setUsername(rst.getString("username"));
admin.setUserpwd(rst.getString("userpwd"));
list.add(admin);
}
rst.close();
pst.close();
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public boolean addAdmin(Admin admin) {
String sql = "INSERT INTO `admina`(`id`,`username`,`userpwd`) VALUES (?,?,?)";
Connection conn = DbHelper.getConnection();
try {
PreparedStatement pst = conn.prepareStatement(sql);
pst.setInt(1, admin.getId());
pst.setString(2, admin.getUsername());
pst.setString(3, admin.getUserpwd());
int count = pst.executeUpdate();
pst.close();
return count > 0 ? true : false;
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
public boolean updateAdmin(Admin admin) {
String sql = "UPDATE `admina` SET `username`=?,`userpwd`=? WHERE `id` = ?";
Connection conn = DbHelper.getConnection();
try {
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, admin.getUsername());
pst.setString(2, admin.getUserpwd());
pst.setInt(3, admin.getId());
int count = pst.executeUpdate();
pst.close();
return count > 0 ? true : false;
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
public boolean deleteAdmin(int id) { // ɾ��
String sql = "delete from admina where id = ?";
Connection conn = DbHelper.getConnection();
try {
PreparedStatement pst = conn.prepareStatement(sql);
pst.setInt(1, id);
int count = pst.executeUpdate();
pst.close();
return count > 0 ? true : false;
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
public Admin selectAdminById(int id) {
Connection conn = DbHelper.getConnection();
String sql = "select * from admina where id = " + id;
Admin admin = null;
try {
PreparedStatement pst = conn.prepareStatement(sql);
ResultSet rst = pst.executeQuery();
while (rst.next()) {
admin = new Admin();
admin.setId(rst.getInt("id"));
admin.setUsername(rst.getString("username"));
admin.setUserpwd(rst.getString("userpwd"));
}
rst.close();
pst.close();
} catch (SQLException e) {
e.printStackTrace();
}
return admin;
}
public Admin selectAdminByUsernameAndPwd(String uname,String pwd) {
Connection conn = DbHelper.getConnection();
String sql = "select * from admina where username = '" + uname + "' and userpwd = '" + pwd + "'";
Admin admin = null;
try {
PreparedStatement pst = conn.prepareStatement(sql);
ResultSet rst = pst.executeQuery();
while (rst.next()) {
admin = new Admin();
admin.setId(rst.getInt("id"));
admin.setUsername(rst.getString("username"));
admin.setUserpwd(rst.getString("userpwd"));
}
rst.close();
pst.close();
} catch (SQLException e) {
e.printStackTrace();
}
return admin;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论















收起资源包目录








































































共 54 条
- 1
资源评论

- mydpkg2018-12-10你这个解压密码多少爱听音乐的孩纸2019-09-09没有解压密码
- hai_chong1232018-11-10个人觉得没有什么用爱听音乐的孩纸2018-12-10这是一个带登陆的基础架子,可以在上面进行扩展

爱听音乐的孩纸
- 粉丝: 81
- 资源: 14
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
