DBCon

package db;

import java.sql.*;

import action.LoginForm;


public class DBCon {
	
	
	static String  url="jdbc:sqlserver://localhost:1433; DatabaseName=L";
	static String user="sa";
	static String password="123";
    public static Connection getConn(){
    	Connection conn=null;
    	try{
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			conn= DriverManager.getConnection(url,user,password);
		}catch(Exception e){
			e.printStackTrace();
		}
	    return conn;
    }
    
    public static boolean login(LoginForm loginForm){
    	boolean flag=false;
    	String sql = "select * from Member where name=? and password=?";
    	System.out.println("sql"+loginForm.getUserName());
		Connection conn=null;
		conn=getConn();
		if(conn==null){
			  System.out.println("conn is null------------------------------------");
		}
		
		PreparedStatement pstm=null;
		ResultSet rs=null;
		try {			
			pstm=conn.prepareStatement(sql);
			
			pstm.setString(1, loginForm.getUserName());
			pstm.setString(2, loginForm.getPassWord());
			rs=pstm.executeQuery();
			if(rs.next()){
				flag=true;
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			close(conn, null, pstm, rs);
		}
    	return flag;
    }
    
    public static void close(Connection conn,Statement st,PreparedStatement ps,ResultSet rs){
		try {
			if(rs!=null){
				rs.close();
				rs=null;
			}
			if(ps!=null){
				ps.close();
				ps=null;
			}
			if(st!=null){
				st.close();
				st=null;
			}
			if(conn!=null){
				conn.close();
				conn=null;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


package dao.Impl; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import db.DBCon; import model.PageBean; import model.UsRole; import model.User; public class EmpBiz { DBCon dbCon=new DBCon(); UsRole usRole; PageBean pageBean; public EmpBiz() { super(); } //具体实现分页的方法,传递两个参数,一个第几页,一个每页的数量 public PageBean listEmps(int pageNo, int pageCount){ ResultSet rs=null; ArrayList<UsRole> list=new ArrayList<UsRole>(); String sqlCount="select count(*) from user"; String sql="select user_id,user_num,user_name,password,phone,role_name " + "from user,role " + "where user.role_id=role.role_id " + "limit "+((pageNo-1)*pageCount)+","+pageCount; rs=dbCon.find(sql); try { /* con=dbCon.dbCon(); st=con.createStatement(); rs=st.executeQuery(sql);*/ while(rs.next()){ int userID = rs.getInt("user_id"); String userNum = rs.getString("user_num"); String userName = rs.getString("user_name"); String pwd = rs.getString("password"); String phone = rs.getString("phone"); String roleName = rs.getString("role_name"); usRole = new UsRole(userID, userNum, userName, pwd, phone, roleName); list.add(usRole); } rs=dbCon.find(sqlCount); // rs=st.executeQuery(sqlCount); int totalCount=0; while(rs.next()){ totalCount=rs.getInt(1); } pageBean=new PageBean(list,totalCount,pageNo,pageCount); return pageBean; } catch (SQLException e) { e.printStackTrace(); // return null; } return pageBean; } }
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雪落夜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值