|
|
|
|
package com.dao;
|
|
|
|
|
|
|
|
|
|
import com.db.DBHelper;
|
|
|
|
|
import com.bean.AdminBean;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.sql.*;
|
|
|
|
|
|
|
|
|
|
public class AdminDao {
|
|
|
|
|
|
|
|
|
|
//<2F><>֤<EFBFBD><D6A4>¼
|
|
|
|
|
public String CheckLogin(String username, String password){
|
|
|
|
|
System.out.println("user"+username+"password"+password);
|
|
|
|
|
String id = null;
|
|
|
|
|
String sql="select * from Admin where Admin_Username='"+username+"' and Admin_Password='"+password+"'";
|
|
|
|
|
Statement stat = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
Connection conn = new DBHelper().getConn();
|
|
|
|
|
try{
|
|
|
|
|
stat = conn.createStatement();
|
|
|
|
|
rs = stat.executeQuery(sql);
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
id = rs.getString("Admin_ID");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(SQLException ex){}
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
//<2F><>֤<EFBFBD><D6A4><EFBFBD><EFBFBD>
|
|
|
|
|
public boolean CheckPassword(String id, String password){
|
|
|
|
|
boolean ps = false;
|
|
|
|
|
String sql="select * from Admin where Admin_ID='"+id+"' and Admin_Password='"+password+"'";
|
|
|
|
|
Statement stat = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
Connection conn = new DBHelper().getConn();
|
|
|
|
|
try{
|
|
|
|
|
stat = conn.createStatement();
|
|
|
|
|
rs = stat.executeQuery(sql);
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
ps=true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(SQLException ex){}
|
|
|
|
|
return ps;
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ȡ<EFBFBD>б<EFBFBD>
|
|
|
|
|
public List<AdminBean> GetList(String strwhere,String strorder){
|
|
|
|
|
String sql="select * from Admin";
|
|
|
|
|
if(!(isInvalid(strwhere)))
|
|
|
|
|
{
|
|
|
|
|
sql+=" where "+strwhere;
|
|
|
|
|
}
|
|
|
|
|
if(!(isInvalid(strorder)))
|
|
|
|
|
{
|
|
|
|
|
sql+=" order by "+strorder;
|
|
|
|
|
}
|
|
|
|
|
Statement stat = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
Connection conn = new DBHelper().getConn();
|
|
|
|
|
List<AdminBean> list=new ArrayList<AdminBean>();
|
|
|
|
|
try{
|
|
|
|
|
stat = conn.createStatement();
|
|
|
|
|
rs = stat.executeQuery(sql);
|
|
|
|
|
while(rs.next()){
|
|
|
|
|
AdminBean cnbean=new AdminBean();
|
|
|
|
|
cnbean.setAdmin_ID(rs.getInt("Admin_ID"));
|
|
|
|
|
cnbean.setAdmin_Username(rs.getString("Admin_Username"));
|
|
|
|
|
cnbean.setAdmin_Password(rs.getString("Admin_Password"));
|
|
|
|
|
cnbean.setAdmin_Name(rs.getString("Admin_Name"));
|
|
|
|
|
cnbean.setAdmin_Sex(rs.getString("Admin_Sex"));
|
|
|
|
|
cnbean.setAdmin_Tel(rs.getString("Admin_Tel"));
|
|
|
|
|
list.add(cnbean);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
if (conn != null)
|
|
|
|
|
conn.close();
|
|
|
|
|
if (stat != null)
|
|
|
|
|
stat.close();
|
|
|
|
|
if (rs != null)
|
|
|
|
|
rs.close();
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><>ȡָ<C8A1><D6B8>ID<49><44>ʵ<EFBFBD><CAB5>Bean
|
|
|
|
|
public AdminBean GetBean(int id){
|
|
|
|
|
String sql="select * from Admin where Admin_ID="+id;
|
|
|
|
|
Statement stat = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
Connection conn = new DBHelper().getConn();
|
|
|
|
|
AdminBean cnbean=new AdminBean();
|
|
|
|
|
try{
|
|
|
|
|
stat = conn.createStatement();
|
|
|
|
|
rs = stat.executeQuery(sql);
|
|
|
|
|
while(rs.next()){
|
|
|
|
|
cnbean.setAdmin_ID(rs.getInt("Admin_ID"));
|
|
|
|
|
cnbean.setAdmin_Username(rs.getString("Admin_Username"));
|
|
|
|
|
cnbean.setAdmin_Password(rs.getString("Admin_Password"));
|
|
|
|
|
cnbean.setAdmin_Name(rs.getString("Admin_Name"));
|
|
|
|
|
cnbean.setAdmin_Sex(rs.getString("Admin_Sex"));
|
|
|
|
|
cnbean.setAdmin_Tel(rs.getString("Admin_Tel"));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
if (conn != null)
|
|
|
|
|
conn.close();
|
|
|
|
|
if (stat != null)
|
|
|
|
|
stat.close();
|
|
|
|
|
if (rs != null)
|
|
|
|
|
rs.close();
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return cnbean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
public void Add(AdminBean cnbean){
|
|
|
|
|
String sql="insert into Admin (";
|
|
|
|
|
sql+="Admin_Username,Admin_Password,Admin_Name,Admin_Sex,Admin_Tel";
|
|
|
|
|
sql+=") values(";
|
|
|
|
|
sql+="'"+cnbean.getAdmin_Username()+"','"+cnbean.getAdmin_Password()+"','"+cnbean.getAdmin_Name()+"','"+cnbean.getAdmin_Sex()+"','"+cnbean.getAdmin_Tel()+"'";
|
|
|
|
|
sql+=")";
|
|
|
|
|
Statement stat = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
Connection conn = new DBHelper().getConn();
|
|
|
|
|
try{
|
|
|
|
|
stat = conn.createStatement();
|
|
|
|
|
stat.executeUpdate(sql);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
if (conn != null)
|
|
|
|
|
conn.close();
|
|
|
|
|
if (stat != null)
|
|
|
|
|
stat.close();
|
|
|
|
|
if (rs != null)
|
|
|
|
|
rs.close();
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><EFBFBD>
|
|
|
|
|
public void Update(AdminBean cnbean){
|
|
|
|
|
String sql="update Admin set ";
|
|
|
|
|
sql+="Admin_Username='"+cnbean.getAdmin_Username()+"',";
|
|
|
|
|
sql+="Admin_Password='"+cnbean.getAdmin_Password()+"',";
|
|
|
|
|
sql+="Admin_Name='"+cnbean.getAdmin_Name()+"',";
|
|
|
|
|
sql+="Admin_Sex='"+cnbean.getAdmin_Sex()+"',";
|
|
|
|
|
sql+="Admin_Tel='"+cnbean.getAdmin_Tel()+"'";
|
|
|
|
|
|
|
|
|
|
sql+=" where Admin_ID='"+cnbean.getAdmin_ID()+"'";
|
|
|
|
|
Statement stat = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
Connection conn = new DBHelper().getConn();
|
|
|
|
|
try{
|
|
|
|
|
stat = conn.createStatement();
|
|
|
|
|
stat.executeUpdate(sql);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
if (conn != null)
|
|
|
|
|
conn.close();
|
|
|
|
|
if (stat != null)
|
|
|
|
|
stat.close();
|
|
|
|
|
if (rs != null)
|
|
|
|
|
rs.close();
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//ɾ<><C9BE>
|
|
|
|
|
public void Delete(String strwhere){
|
|
|
|
|
String sql="delete Admin where ";
|
|
|
|
|
sql+=strwhere;
|
|
|
|
|
Statement stat = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
Connection conn = new DBHelper().getConn();
|
|
|
|
|
try{
|
|
|
|
|
stat = conn.createStatement();
|
|
|
|
|
stat.executeUpdate(sql);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
if (conn != null)
|
|
|
|
|
conn.close();
|
|
|
|
|
if (stat != null)
|
|
|
|
|
stat.close();
|
|
|
|
|
if (rs != null)
|
|
|
|
|
rs.close();
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>ֵ
|
|
|
|
|
private boolean isInvalid(String value) {
|
|
|
|
|
return (value == null || value.length() == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
System.out.println("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|