⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dao.java

📁 网上选课系统 JSP + ACCESS数据库 供参考 如有不足 请指点
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			// TODO Auto-generated catch block
			e.printStackTrace();
			onclose();
		}
		return res;
	}

	public void deleteStu(String xuehao) {

		try {
			stmt = conn
					.prepareStatement("delete from wp_student where xuehao=?");
			stmt.setString(1, xuehao);
			stmt.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			onclose();
		}

	}

	// ****************�γ̹���*************************************

	public boolean addCource(String courcename, String teacher, String jiaoshi,
			String time, float score) throws SQLException// ����������ֵ��ʾע��ɹ������ؼ�ֵ��ʾע��ʧ��
	{

		boolean bo = false;// ��ʾע��ʧ��

		try {
			conn.setAutoCommit(false);
			stmt = conn
					.prepareStatement("insert into wp_cource(id,courcename,teacher,jiaoshi,time,score) values(?,?,?,?,?,?)");// �������û���Ϣ
			stmt.setInt(1, selectId());
			stmt.setString(2, courcename);// ����
			stmt.setString(3, teacher);// ���Dz���
			stmt.setString(4, jiaoshi);
			stmt.setString(5, time);
			stmt.setFloat(6, score);
			stmt.execute();// ִ��
			bo = true;
			conn.commit();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			conn.rollback();
			e.printStackTrace();
			onclose();
		}
		return bo;
	}

	public int coutotalpage() {
		int totalpage = 0;

		ResultSet res = null;
		String sql = "select count(*) from wp_cource";
		try {
			stmt = conn.prepareStatement(sql);
			res = stmt.executeQuery();
			if (res.next()) {
				int x = res.getInt(1);
				if (x % 10 == 0) {
					totalpage = x / 10;
				} else
					totalpage = ((x - x % 10) / 10) + 1;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			onclose();
		}
		return totalpage;
	}

	public ResultSet coupagers(int topage)// ��ҳ����
	{

		ResultSet res = null;
		try {
			String sql = "select * from ( select rownum r,id,courcename,teacher,jiaoshi,time,score from wp_cource )  where  r between ? and ? ";
			stmt = conn.prepareStatement(sql);
			if(topage == 1){
				stmt.setInt(1, (topage - 1) * 10);
				stmt.setInt(2, ((topage - 1) * 10) + 10);
			}else{
				stmt.setInt(1, (topage - 1) * 10+1);
				stmt.setInt(2, ((topage - 1) * 10) + 10);
			}
			
			res = stmt.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			onclose();
		}
		return res;
	}

	public void deleteCou(String courcename) {

		try {
			stmt = conn
					.prepareStatement("delete from wp_cource where courcename=?");
			stmt.setString(1, courcename);
			stmt.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			onclose();
		}

	}

	// **********************ѡ��ģ��**************************
	public boolean addChoose(int id,String courcename, String teacher, String jiaoshi,
			String time, float score, String xuehao) throws SQLException// ����������ֵ��ʾע��ɹ������ؼ�ֵ��ʾע��ʧ��
	{

		boolean bo = false;// ��ʾע��ʧ��

		try {
			conn.setAutoCommit(false);
			stmt = conn
					.prepareStatement("insert into wp_classt(id,courcename,teacher,jiaoshi,time,score,xuehao) values(?,?,?,?,?,?,?)");// �������û���Ϣ
			stmt.setInt(1, selectId());
			stmt.setString(2, courcename);// ����
			stmt.setString(3, teacher);// ���Dz���
			stmt.setString(4, jiaoshi);
			stmt.setString(5, time);
			stmt.setFloat(6, score);
			stmt.setString(7, xuehao);
			stmt.execute();// ִ��
			bo = true;// ��ʾע��ɹ�
			conn.commit();

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			conn.rollback();
			e.printStackTrace();
			onclose();
		}
		return bo;
	}

	public int clatotalpage() {
		int totalpage = 0;

		ResultSet res = null;
		String sql = "select count(*) from wp_classt";
		try {
			stmt = conn.prepareStatement(sql);
			res = stmt.executeQuery();
			if (res.next()) {
				int x = res.getInt(1);
				System.out.println(x);
				if (x % 10 == 0) {
					totalpage = x / 10;
				} else
					totalpage = ((x - x % 10) / 10) + 1;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			onclose();
		}
		return totalpage;
	}

	public ResultSet clapagers(int topage)// ��ҳ����
	{

		String sql = "select * from ( select rownum r,id,courcename,teacher,jiaoshi,time,score from wp_cource) where r between ? and ?";
		ResultSet res = null;
		try {
			stmt = conn
					.prepareStatement(sql);
			if(topage == 1){
				stmt.setInt(1, (topage - 1) * 10);
				stmt.setInt(2, ((topage - 1) * 10) + 10);
			}else{
				stmt.setInt(1, (topage - 1) * 10+1);
				stmt.setInt(2, ((topage - 1) * 10) + 10);
			}
			res = stmt.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			onclose();
		}
		return res;
	}

	public ResultSet selCource(String cource) {

		ResultSet res = null;
		try {
			stmt = conn
					.prepareStatement("select * from wp_cource where courcename=?");
			stmt.setString(1, cource);
			res = stmt.executeQuery();

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			onclose();
		}
		return res;

	}

	// *****************************����****************************************************
	public int chatotalpage() {
		int totalpage = 0;

		ResultSet res = null;
		String sql = "select count(*) from wp_classt";
		try {
			stmt = conn.prepareStatement(sql);
			res = stmt.executeQuery();
			if (res.next()) {
				int x = res.getInt(1);
				if (x % 10 == 0) {
					totalpage = x / 10;
				} else
					totalpage = ((x - x % 10) / 10) + 1;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			onclose();
		}
		return totalpage;
	}

	public ResultSet chapagers(int topage)// ��ҳ����
	{

		ResultSet res = null;
		try {
			stmt = conn
					.prepareStatement("select * from ( select rownum r,id,courcename,teacher,jiaoshi,time,score,xuehao from wp_classt) where r between ? and ?");
			if(topage == 1){
				stmt.setInt(1, (topage - 1) * 10);
				stmt.setInt(2, ((topage - 1) * 10) + 10);
			}else{
				stmt.setInt(1, (topage - 1) * 10+1);
				stmt.setInt(2, ((topage - 1) * 10) + 10);
			}
			res = stmt.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			onclose();
		}
		return res;
	}

	public void delcha(String courcename) {

		try {
			stmt = conn
					.prepareStatement("delete from wp_classt where courcename=?");
			stmt.setString(1, courcename);
			stmt.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			onclose();
		}

	}

	// ************************�ر�********************************
	public void onclose() {
		if (stmt != null) {
			try {
				stmt.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -