package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import model.*;

public class LoginJdbc {
	Connection conn = null;
	Statement st = null;
	ResultSet rs = null;

	Manager man = null;
	Teacher tea = null;
	Student stu = null;

	String driver = "com.mysql.jdbc.Driver"; // ������
	String url = "jdbc:mysql://localhost:3306/selectcourse?useUnicode=true&characterEncoding=utf8";
	String user = "root";
	String password = "root";

	// ����Ա��¼
	public Manager login(int id) {
		String sql = "select * from manager where id=" + id;
		try {
			Class.forName(driver);
			conn = DriverManager.getConnection(url, user, password); // ��ȡ����ݿ������
			st = conn.createStatement();// ��ȡ��������ݿⷢ��SQL���
			rs = st.executeQuery(sql); // ����ݿⷢ��SQL��䣬����ȡ�����
			while (rs.next()) {
				int mid = rs.getInt(1);
				String name = rs.getString(2);
				String pwd = rs.getString(3);
				int age = rs.getInt(4);
				man = new Manager(mid, name, pwd, age);
			}

		} catch (Exception e) {
			close();
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return man;
	}

	// ��ʦ��¼
	public Teacher tealogin(int id) {
		String sql = "select * from teacher where id=" + id;
		try {
			Class.forName(driver);
			conn = DriverManager.getConnection(url, user, password); // ��ȡ����ݿ������
			st = conn.createStatement();// ��ȡ��������ݿⷢ��SQL���
			rs = st.executeQuery(sql); // ����ݿⷢ��SQL��䣬����ȡ�����
			while (rs.next()) {
				int tid = rs.getInt(1);
				String name = rs.getString(2);
				String pwd = rs.getString(3);
				String title = rs.getString(4);
				String department = rs.getString(5);
				tea = new Teacher(tid, name, pwd, title, department);
			}

		} catch (Exception e) {
			close();
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return tea;
	}

	// ѧ���¼
	public Student stulogin(int id) {
		String sql = "select * from student where id=" + id;
		try {
			Class.forName(driver);//������
			conn = DriverManager.getConnection(url, user, password); // ��ȡ����ݿ������
			st = conn.createStatement();// ��ȡ��������ݿⷢ��SQL���
			rs = st.executeQuery(sql); // ����ݿⷢ��SQL��䣬����ȡ�����
			while (rs.next()) {
				int sid = rs.getInt(1);
				String name = rs.getString(2);
				String pwd = rs.getString(3);
				String bj = rs.getString(4);
				String home = rs.getString(5);
				int phone = rs.getInt(6);
				String email = rs.getString(7);

				stu = new Student(sid, name, pwd, bj, home, phone, email);
			}

		} catch (Exception e) {
			close();
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return stu;
	}

	public void close() {
		try {
			if (rs != null)
				rs.close();
			if (st != null)
				st.close();
			if (conn != null)
				conn.close();
		} catch (SQLException e) {

			e.printStackTrace();
		}
	}

}
最近下载更多
wuyanmingsi  LV1 2024年10月15日
一勺枣糕  LV3 2024年6月19日
tmf852  LV5 2023年6月10日
Tayirjan  LV11 2023年3月23日
263648  LV7 2022年6月23日
ouyun12345  LV4 2022年5月17日
微信网友_5764743416303616  LV6 2022年4月25日
kuoluoluo  LV3 2022年4月18日
朱朱啊哈  LV16 2022年3月4日
123123123W  LV7 2022年2月28日
最近浏览更多
Maomaoyun 6月10日
暂无贡献等级
2297224153 3月27日
暂无贡献等级
652654393  LV5 2024年12月18日
11onerr 2024年11月22日
暂无贡献等级
111rose  LV1 2024年11月21日
wsq123456 2024年11月20日
暂无贡献等级
wuyanmingsi  LV1 2024年9月7日
GQpqwe 2024年8月14日
暂无贡献等级
琐事消极 2024年7月1日
暂无贡献等级
时光海  LV2 2024年6月30日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友