parent
b2c17bcc07
commit
634cd11b18
@ -0,0 +1,224 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
//删除
|
||||
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("");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,202 @@
|
||||
package com.dao;
|
||||
|
||||
import com.bean.Repair_addBean;
|
||||
import com.db.DBHelper;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RepairDao {
|
||||
//获取列表
|
||||
public List<Repair_addBean> GetList(String strwhere, String strorder){
|
||||
String sql="select * from repair ";
|
||||
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<Repair_addBean> list=new ArrayList<Repair_addBean>();
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
rs = stat.executeQuery(sql);
|
||||
while(rs.next()){
|
||||
Repair_addBean cnbean=new Repair_addBean();
|
||||
// cnbean.setRepair_time((rs.getInt("Repair_time")));
|
||||
cnbean.setRepair_id(rs.getInt("repair_id"));
|
||||
cnbean.setRepair_info(rs.getString("repair_info"));
|
||||
cnbean.setRepair_address(rs.getString("repair_address"));
|
||||
//cnbean.setRepair_info(rs.getString("repair_info;"));
|
||||
// cnbean.setRepair_cost(rs.getString("repair_cost"));
|
||||
cnbean.setRepair_tel(rs.getString("repair_tel"));
|
||||
cnbean.setRepair_status(rs.getString("repair_status"));
|
||||
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 Repair_addBean GetBean(int id){
|
||||
|
||||
String sql="select * from repair where repair_id="+id;
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn = new DBHelper().getConn();
|
||||
Repair_addBean cnbean=new Repair_addBean();
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
rs = stat.executeQuery(sql);
|
||||
while(rs.next()){
|
||||
cnbean.setRepair_id(rs.getInt("repair_id"));
|
||||
// cnbean.setRepair_info(rs.getString("repair_info"));
|
||||
// cnbean.setRepair_address(rs.getString("repair_address"));
|
||||
// cnbean.setRepair_tel(rs.getString("repair_tel"));
|
||||
cnbean.setRepair_status(rs.getString("repair_status"));
|
||||
// cnbean.setTeacher_Tel(rs.getString("Teacher_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(Repair_addBean cnbean){
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
String sql="insert into repair (";
|
||||
sql+="repair_id,repair_info,repair_address,repair_tel";
|
||||
sql+=") values(";
|
||||
sql+="'"+cnbean.getRepair_id()+"','"+cnbean.getRepair_info()+"','"+cnbean.getRepair_address()+"','"+cnbean.getRepair_tel()+"'";
|
||||
|
||||
sql+=")";
|
||||
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(Repair_addBean cnbean){
|
||||
String sql="update repair set ";
|
||||
// sql+="repair_id='"+cnbean.getRepair_id()+"',";
|
||||
// sql+="repair_info='"+cnbean.getRepair_info()+"',";
|
||||
//sql+="repair_address='"+cnbean.getRepair_address()+"',";
|
||||
// sql+="repair_tel='"+cnbean.getRepair_tel()+"',";
|
||||
sql+="repair_status='"+cnbean.getRepair_status()+"'";
|
||||
|
||||
sql+=" where repair_id='"+cnbean.getRepair_id()+"'";
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn = new DBHelper().getConn();
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
stat.executeUpdate(sql);
|
||||
System.out.println(sql);
|
||||
System.out.println("修改状态成功");
|
||||
} 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 Delete(String strwhere){
|
||||
String sql="delete repair 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("");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,462 @@
|
||||
package com.dao;
|
||||
|
||||
import com.bean.StudentBean;
|
||||
import com.db.DBHelper;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StudentDao {
|
||||
|
||||
//验证登录
|
||||
public String CheckLogin(String username, String password){
|
||||
String id = null;
|
||||
String sql="select * from Student where Student_Username='"+username+"' and Student_Password='"+password+"' or Student_State='入住'";
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
System.out.println(sql);
|
||||
Connection conn = new DBHelper().getConn();
|
||||
System.out.println(conn);
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
rs = stat.executeQuery(sql);
|
||||
while (rs.next()) {
|
||||
id = rs.getString("Student_ID");
|
||||
}
|
||||
}
|
||||
catch(SQLException ex){
|
||||
System.out.println(ex);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
//验证密码
|
||||
public boolean CheckPassword(String id, String password){
|
||||
boolean ps = false;
|
||||
String sql="select * from Student where Student_ID='"+id+"' and Student_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<StudentBean> GetAllList(String strwhere,String strorder){
|
||||
String sql="select *from Student";
|
||||
// String sql1="select count(*) from Student";
|
||||
if(!(isInvalid(strwhere)))
|
||||
{
|
||||
sql+=" where "+strwhere;
|
||||
}
|
||||
if(!(isInvalid(strorder)))
|
||||
{
|
||||
sql+=" order by "+strorder;
|
||||
}
|
||||
System.out.println(sql);
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
// String count="";
|
||||
Connection conn = new DBHelper().getConn();
|
||||
List<StudentBean> list=new ArrayList<StudentBean>();
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
rs = stat.executeQuery(sql);
|
||||
// count= String.valueOf(stat.executeQuery(sql1));
|
||||
// System.out.println(count);
|
||||
HttpSession session = ServletActionContext.getRequest().getSession();
|
||||
// session.setAttribute("number", count);
|
||||
while(rs.next()){
|
||||
StudentBean cnbean=new StudentBean();
|
||||
cnbean.setStudent_ID(rs.getInt("Student_ID"));
|
||||
cnbean.setStudent_DomitoryID(rs.getInt("Student_DomitoryID"));
|
||||
cnbean.setStudent_Username(rs.getString("Student_Username"));
|
||||
cnbean.setStudent_Password(rs.getString("Student_Password"));
|
||||
cnbean.setStudent_Name(rs.getString("Student_Name"));
|
||||
cnbean.setStudent_Sex(rs.getString("Student_Sex"));
|
||||
cnbean.setStudent_Class(rs.getString("Student_Class"));
|
||||
cnbean.setStudent_State(rs.getString("Student_State"));
|
||||
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;
|
||||
}
|
||||
public List<StudentBean> GetAllList1(int a){
|
||||
|
||||
|
||||
System.out.println(a);
|
||||
a=a*16;
|
||||
int b=16;
|
||||
System.out.println("a"+a);
|
||||
System.out.println("b"+b);
|
||||
String sql="select *from Student LIMIT ";
|
||||
sql+=a+","+b;
|
||||
String sql1="select count(*) from Student";
|
||||
System.out.println(sql);
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
String count="";
|
||||
Connection conn = new DBHelper().getConn();
|
||||
List<StudentBean> list=new ArrayList<StudentBean>();
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
rs = stat.executeQuery(sql);
|
||||
// count= String.valueOf(stat.executeQuery(sql1));
|
||||
System.out.println(count);
|
||||
// HttpSession session = ServletActionContext.getRequest().getSession();
|
||||
//// session.setAttribute("number", count);
|
||||
while(rs.next()){
|
||||
StudentBean cnbean=new StudentBean();
|
||||
cnbean.setStudent_ID(rs.getInt("Student_ID"));
|
||||
cnbean.setStudent_DomitoryID(rs.getInt("Student_DomitoryID"));
|
||||
cnbean.setStudent_Username(rs.getString("Student_Username"));
|
||||
cnbean.setStudent_Password(rs.getString("Student_Password"));
|
||||
cnbean.setStudent_Name(rs.getString("Student_Name"));
|
||||
cnbean.setStudent_Sex(rs.getString("Student_Sex"));
|
||||
cnbean.setStudent_Class(rs.getString("Student_Class"));
|
||||
cnbean.setStudent_State(rs.getString("Student_State"));
|
||||
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;
|
||||
}
|
||||
//获取列表
|
||||
public List<StudentBean> GetList(String strwhere,String strorder){
|
||||
String sql="select * from Student,Domitory,Building where Student_DomitoryID=Domitory_ID and Domitory_BuildingID=Building_ID";
|
||||
if(!(isInvalid(strwhere)))
|
||||
{
|
||||
sql+=" and "+strwhere;
|
||||
}
|
||||
if(!(isInvalid(strorder)))
|
||||
{
|
||||
sql+=" order by "+strorder;
|
||||
}
|
||||
// System.out.println(sql);
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn = new DBHelper().getConn();
|
||||
List<StudentBean> list=new ArrayList<StudentBean>();
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
rs = stat.executeQuery(sql);
|
||||
while(rs.next()){
|
||||
StudentBean cnbean=new StudentBean();
|
||||
cnbean.setStudent_ID(rs.getInt("Student_ID"));
|
||||
cnbean.setStudent_DomitoryID(rs.getInt("Student_DomitoryID"));
|
||||
cnbean.setStudent_Username(rs.getString("Student_Username"));
|
||||
cnbean.setStudent_Password(rs.getString("Student_Password"));
|
||||
cnbean.setStudent_Name(rs.getString("Student_Name"));
|
||||
cnbean.setStudent_Sex(rs.getString("Student_Sex"));
|
||||
cnbean.setStudent_Class(rs.getString("Student_Class"));
|
||||
cnbean.setStudent_State(rs.getString("Student_State"));
|
||||
cnbean.setDomitory_Name(rs.getString("Domitory_Name"));
|
||||
cnbean.setBuilding_Name(rs.getString("Building_Name"));
|
||||
cnbean.setDomitory_Type(rs.getString("Domitory_Type"));
|
||||
cnbean.setDomitory_Number(rs.getString("Domitory_Number"));
|
||||
cnbean.setDomitory_Tel(rs.getString("Domitory_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 StudentBean GetAllFirstBean(String strwhere){
|
||||
String sql="select * from Student where "+strwhere;
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn = new DBHelper().getConn();
|
||||
StudentBean cnbean=new StudentBean();
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
rs = stat.executeQuery(sql);
|
||||
if(rs.next()){
|
||||
cnbean.setStudent_ID(rs.getInt("Student_ID"));
|
||||
cnbean.setStudent_DomitoryID(rs.getInt("Student_DomitoryID"));
|
||||
cnbean.setStudent_Username(rs.getString("Student_Username"));
|
||||
cnbean.setStudent_Password(rs.getString("Student_Password"));
|
||||
cnbean.setStudent_Name(rs.getString("Student_Name"));
|
||||
cnbean.setStudent_Sex(rs.getString("Student_Sex"));
|
||||
cnbean.setStudent_Class(rs.getString("Student_Class"));
|
||||
cnbean.setStudent_State(rs.getString("Student_State"));
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
//获取指定ID的实体Bean
|
||||
public StudentBean GetFirstBean(String strwhere){
|
||||
String sql="select * from Student,Domitory,Building where Student_DomitoryID=Domitory_ID and Domitory_BuildingID=Building_ID and "+strwhere;
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn = new DBHelper().getConn();
|
||||
StudentBean cnbean=new StudentBean();
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
rs = stat.executeQuery(sql);
|
||||
if(rs.next()){
|
||||
cnbean.setStudent_ID(rs.getInt("Student_ID"));
|
||||
cnbean.setStudent_DomitoryID(rs.getInt("Student_DomitoryID"));
|
||||
cnbean.setStudent_Username(rs.getString("Student_Username"));
|
||||
cnbean.setStudent_Password(rs.getString("Student_Password"));
|
||||
cnbean.setStudent_Name(rs.getString("Student_Name"));
|
||||
cnbean.setStudent_Sex(rs.getString("Student_Sex"));
|
||||
cnbean.setStudent_Class(rs.getString("Student_Class"));
|
||||
cnbean.setStudent_State(rs.getString("Student_State"));
|
||||
cnbean.setDomitory_Name(rs.getString("Domitory_Name"));
|
||||
cnbean.setDomitory_Number(rs.getString("Domitory_Number"));
|
||||
cnbean.setBuilding_Name(rs.getString("Building_Name"));
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
//获取指定ID的实体Bean
|
||||
public StudentBean GetAllBean(int id){
|
||||
String sql="select * from Student where Student_ID="+id;
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn = new DBHelper().getConn();
|
||||
StudentBean cnbean=new StudentBean();
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
rs = stat.executeQuery(sql);
|
||||
while(rs.next()){
|
||||
cnbean.setStudent_ID(rs.getInt("Student_ID"));
|
||||
cnbean.setStudent_DomitoryID(rs.getInt("Student_DomitoryID"));
|
||||
cnbean.setStudent_Username(rs.getString("Student_Username"));
|
||||
cnbean.setStudent_Password(rs.getString("Student_Password"));
|
||||
cnbean.setStudent_Name(rs.getString("Student_Name"));
|
||||
cnbean.setStudent_Sex(rs.getString("Student_Sex"));
|
||||
cnbean.setStudent_Class(rs.getString("Student_Class"));
|
||||
cnbean.setStudent_State(rs.getString("Student_State"));
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
//获取指定ID的实体Bean
|
||||
public StudentBean GetBean(int id){
|
||||
String sql="select * from Student,Domitory,Building where Student_DomitoryID=Student_DomitoryID and where Building_ID=Building and where Student_ID="+id;
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn = new DBHelper().getConn();
|
||||
StudentBean cnbean=new StudentBean();
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
rs = stat.executeQuery(sql);
|
||||
while(rs.next()){
|
||||
cnbean.setStudent_ID(rs.getInt("Student_ID"));
|
||||
cnbean.setStudent_DomitoryID(rs.getInt("Student_DomitoryID"));
|
||||
cnbean.setStudent_Username(rs.getString("Student_Username"));
|
||||
cnbean.setStudent_Password(rs.getString("Student_Password"));
|
||||
cnbean.setStudent_Name(rs.getString("Student_Name"));
|
||||
cnbean.setStudent_Sex(rs.getString("Student_Sex"));
|
||||
cnbean.setStudent_Class(rs.getString("Student_Class"));
|
||||
cnbean.setStudent_State(rs.getString("Student_State"));
|
||||
cnbean.setDomitory_Name(rs.getString("Domitory_Name"));
|
||||
cnbean.setBuilding_Name(rs.getString("Building_Name"));
|
||||
}
|
||||
} 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(StudentBean cnbean){
|
||||
String sql="insert into Student (";
|
||||
sql+="Student_DomitoryID,Student_Username,Student_Password,Student_Name,Student_Sex,Student_Class,Student_State";
|
||||
sql+=") values(";
|
||||
sql+="'"+cnbean.getStudent_DomitoryID()+"','"+cnbean.getStudent_Username()+"','"+cnbean.getStudent_Password()+"','"+cnbean.getStudent_Name()+"','"+cnbean.getStudent_Sex()+"','"+cnbean.getStudent_Class()+"','"+cnbean.getStudent_State()+"'";
|
||||
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(StudentBean cnbean){
|
||||
String sql="update Student set ";
|
||||
sql+="Student_DomitoryID='"+cnbean.getStudent_DomitoryID()+"',";
|
||||
sql+="Student_Username='"+cnbean.getStudent_Username()+"',";
|
||||
sql+="Student_Password='"+cnbean.getStudent_Password()+"',";
|
||||
sql+="Student_Name='"+cnbean.getStudent_Name()+"',";
|
||||
sql+="Student_Sex='"+cnbean.getStudent_Sex()+"',";
|
||||
sql+="Student_Class='"+cnbean.getStudent_Class()+"',";
|
||||
sql+="Student_State='"+cnbean.getStudent_State()+"'";
|
||||
|
||||
sql+=" where Student_ID='"+cnbean.getStudent_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();
|
||||
}
|
||||
}
|
||||
}
|
||||
//删除
|
||||
public void Delete(int id){
|
||||
String sql="delete from student where Student_ID="+id;
|
||||
//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("");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,231 @@
|
||||
package com.dao;
|
||||
|
||||
import com.db.DBHelper;
|
||||
import com.bean.TeacherBean;
|
||||
|
||||
import java.util.*;
|
||||
import java.sql.*;
|
||||
|
||||
public class TeacherDao {
|
||||
|
||||
//验证登录
|
||||
public String CheckLogin(String username, String password){
|
||||
System.out.println("user"+username+"password"+password);
|
||||
String id = null;
|
||||
String sql="select * from Teacher where Teacher_Username='"+username+"' and Teacher_Password='"+password+"'";
|
||||
System.out.println(sql);
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn = new DBHelper().getConn();
|
||||
System.out.println(conn);
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
rs = stat.executeQuery(sql);
|
||||
while (rs.next()) {
|
||||
id = rs.getString("Teacher_ID");
|
||||
}
|
||||
}
|
||||
catch(SQLException ex){
|
||||
System.out.println(ex);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
//验证密码
|
||||
public boolean CheckPassword(String id, String password){
|
||||
boolean ps = false;
|
||||
String sql="select * from Teacher where Teacher_ID='"+id+"' and Teacher_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<TeacherBean> GetList(String strwhere,String strorder){
|
||||
String sql="select * from Teacher";
|
||||
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<TeacherBean> list=new ArrayList<TeacherBean>();
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
rs = stat.executeQuery(sql);
|
||||
while(rs.next()){
|
||||
TeacherBean cnbean=new TeacherBean();
|
||||
cnbean.setTeacher_ID(rs.getInt("Teacher_ID"));
|
||||
cnbean.setTeacher_Username(rs.getString("Teacher_Username"));
|
||||
cnbean.setTeacher_Password(rs.getString("Teacher_Password"));
|
||||
cnbean.setTeacher_Name(rs.getString("Teacher_Name"));
|
||||
cnbean.setTeacher_Sex(rs.getString("Teacher_Sex"));
|
||||
cnbean.setTeacher_Tel(rs.getString("Teacher_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 TeacherBean GetBean(int id){
|
||||
String sql="select * from Teacher where Teacher_ID="+id;
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn = new DBHelper().getConn();
|
||||
TeacherBean cnbean=new TeacherBean();
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
rs = stat.executeQuery(sql);
|
||||
while(rs.next()){
|
||||
cnbean.setTeacher_ID(rs.getInt("Teacher_ID"));
|
||||
cnbean.setTeacher_Username(rs.getString("Teacher_Username"));
|
||||
cnbean.setTeacher_Password(rs.getString("Teacher_Password"));
|
||||
cnbean.setTeacher_Name(rs.getString("Teacher_Name"));
|
||||
cnbean.setTeacher_Sex(rs.getString("Teacher_Sex"));
|
||||
cnbean.setTeacher_Tel(rs.getString("Teacher_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(TeacherBean cnbean){
|
||||
String sql="insert into Teacher (";
|
||||
sql+="Teacher_Username,Teacher_Password,Teacher_Name,Teacher_Sex,Teacher_Tel";
|
||||
sql+=") values(";
|
||||
sql+="'"+cnbean.getTeacher_Username()+"','"+cnbean.getTeacher_Password()+"','"+cnbean.getTeacher_Name()+"','"+cnbean.getTeacher_Sex()+"','"+cnbean.getTeacher_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(TeacherBean cnbean){
|
||||
String sql="update Teacher set ";
|
||||
sql+="Teacher_Username='"+cnbean.getTeacher_Username()+"',";
|
||||
sql+="Teacher_Password='"+cnbean.getTeacher_Password()+"',";
|
||||
sql+="Teacher_Name='"+cnbean.getTeacher_Name()+"',";
|
||||
sql+="Teacher_Sex='"+cnbean.getTeacher_Sex()+"',";
|
||||
sql+="Teacher_Tel='"+cnbean.getTeacher_Tel()+"'";
|
||||
|
||||
sql+=" where Teacher_ID='"+cnbean.getTeacher_ID()+"'";
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn = new DBHelper().getConn();
|
||||
try{
|
||||
stat = conn.createStatement();
|
||||
stat.executeUpdate(sql);
|
||||
System.out.println(sql);
|
||||
System.out.println("修改状态成功");
|
||||
} 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 Delete(int id){
|
||||
String sql="delete from teacher where Teacher_ID="+id;
|
||||
//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("");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue