|
|
package com.dao;
|
|
|
|
|
|
import com.db.DBHelper;
|
|
|
import com.bean.AdminBean;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.sql.*;
|
|
|
|
|
|
public class AdminDao {
|
|
|
|
|
|
//駱聯되쩌
|
|
|
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;
|
|
|
}
|
|
|
//駱聯쵱쯤
|
|
|
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;
|
|
|
}
|
|
|
//삿혤죗깊
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
//삿혤寧땍ID돨茄竟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;
|
|
|
}
|
|
|
|
|
|
//警속
|
|
|
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();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//錦맣
|
|
|
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();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//<2F>뇜
|
|
|
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();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//털뙤角뤠왕令
|
|
|
private boolean isInvalid(String value) {
|
|
|
return (value == null || value.length() == 0);
|
|
|
}
|
|
|
|
|
|
//꿎桿
|
|
|
public static void main(String[] args) {
|
|
|
System.out.println("");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|