首页 > 代码库 > 学生选课系统---AdminitartorDAO

学生选课系统---AdminitartorDAO

  学生信息操作:

package com.csms.dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import com.csms.DBLink;import com.csms.entity.Adminitartor;/** * @author 李佩 *  * @version v1 *  * @time 2016/12/2 18:43 *  * @program 管理员信息与数据库进行操作的类 * */public class AdminitartorDAO {	// 管理员登录确认	public Boolean loginConfirm(String name, String password) {		// 实例化管理员对象		Adminitartor admin = new Adminitartor();		// 1.获得数据库连接对象		Connection conn = DBLink.getConn();		// 2.查询管理员的sql语句		String sql = "SELECT loginName,loginPsd FROM adminitrator";		Statement stm = null;		ResultSet rs = null;		try {			// 3.将sql语句发送,执行查询			stm = conn.createStatement();			rs = stm.executeQuery(sql);			while (rs.next()) {				admin.setLoginName(rs.getString("loginName"));				admin.setLoginPSD(rs.getString("loginPsd"));				if (name.equals(admin.getLoginName()) && password.equals(admin.getLoginPSD())) {					return true;				}			}			rs.close();		} catch (Exception e) {			e.printStackTrace();		} finally {			// 4.操作完毕,释放连接			try {				if (stm != null)					stm.close();			} catch (SQLException e) {				// TODO Auto-generated catch block				e.printStackTrace();			}		}		return false;	}		// 取得管理员的所有的身份信息	public Adminitartor getInformation(String userName, String userPsd){		Adminitartor admin = null;		Connection conn = DBLink.getConn();		String sql = "SELECT admiID,admiName,admiAge,admiGender,admiPhone,admiAddress FROM adminitrator WHERE loginName=? AND loginPsd=?";		PreparedStatement ptm = null;		ResultSet rs = null;				try{			ptm = conn.prepareStatement(sql);			ptm.setString(1, userName);			ptm.setString(2, userPsd);			rs = ptm.executeQuery();			while(rs.next()){				admin = new Adminitartor();				admin.setAdminID(rs.getString("admiID"));				admin.setAdminName(rs.getString("admiName"));				admin.setAdminAge(rs.getInt("admiAge"));				admin.setAdminGender(rs.getString("admiGender"));				admin.setAdminPhone(rs.getString("admiPhone"));				admin.setAdminAddress(rs.getString("admiAddress"));			}			rs.close();		}catch(SQLException e){			e.printStackTrace();		}finally{			try{				if(ptm!=null){					ptm.close();				}			}catch(SQLException e){				e.printStackTrace();			}		}				return admin;			}}

  

学生选课系统---AdminitartorDAO