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

📄 pagedao.java

📁 本方案是在与***信息技术(北京)有限公司相关人员协商并分析了北京****投资有限公司综合信息管理系统(以下简称“**管理系统”)相关资料之后提交的网络安全解决方案。 本方案描述***管理系统的网络
💻 JAVA
字号:
package com.test.dao;

import com.test.dao.pool.*;
import com.test.dao.userpage.*;
import com.test.model.LoginBean;
import com.test.model.RoleBean;
import com.test.model.UserBean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

public class PageDAO {
	private ConnectionPool connectionPool;
	private Connection connection;

	public PageDAO() {
		try {
			connectionPool = ConnectionPool.getConnectionPool();
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

	private Connection getConnection() {
		try {
			return connectionPool.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException("无法得到数据库连接");
		}
	}

	private void closeConnection() {
		try {
			this.connection.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public IPage getDataByPageIndex(int pageIndex) {
		try {
			// 使用pageManage得到数据并返回
			PageManage pm = PageManage.newInstance(PageManage.USERBEAN, 10);
			this.connection = this.getConnection();
			return pm.queryByPageIndex(connection, pageIndex);
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		} finally {
			this.closeConnection();
		}
	}
	
	/**
	 * 查询多个管理员
	 * @param sqlText sql查询字符串
	 * @return 包含多个用户的集合
	 */
	public List<LoginBean> query(String sqlText) {
		try {
			connection = this.getConnection();
			Statement stat = connection.createStatement();
			ResultSet rs = stat.executeQuery(sqlText);
			List<LoginBean> admins = new java.util.ArrayList<LoginBean>();
			while (rs.next()) {
				LoginBean user = new LoginBean();
				user.setUser_id(rs.getInt(1) );
				user.setUsername(rs.getString(2));
				user.setPassword(rs.getString(3));
				user.setLogout( rs.getBoolean(4));
				user.setState_pwf(rs.getBoolean(5));
				user.setState_lb(rs.getBoolean(6));
				admins.add(user);
			}
			rs.close();
			stat.close();
			return admins;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException("查询管理员失败,请重试");
		} finally {
			this.closeConnection();
		}
	}
	
	/**
	 * 更新数据的方法
	 * @param sqlText  更新字符串sql
	 */
	public void update( String sqlText) {
		try {
			connection = this.getConnection();
			Statement stat = connection.createStatement();
			stat.executeUpdate(sqlText);
			stat.close();
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException("数据更新失败,请重试");
		} finally {
			this.closeConnection();
		}
	}
	
}

⌨️ 快捷键说明

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