www.pudn.com > Jsp-Blog.rar > LoginDao.java, change:2010-05-24,size:801b


package myblog.dao; 
 
import java.sql.Connection; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
 
import myblog.commons.ConnectionPool; 
 
public class LoginDao { 
	public Connection conn = null; 
 
	public PreparedStatement pstmt = null; 
 
	public ResultSet rs = null; 
 
	public int login(String username, String password) { 
		int num = 0; 
		conn = ConnectionPool.getConnection(); 
		String sql = "select user_name,user_pw from users where user_name=? and user_pw=?"; 
		try { 
			pstmt = conn.prepareStatement(sql); 
			pstmt.setString(1, username); 
			pstmt.setString(2, password); 
			rs = pstmt.executeQuery(); 
			while (rs.next()) { 
				num = 1; 
			} 
		} catch (SQLException e) { 
			e.printStackTrace(); 
		} 
		return num; 
	} 
 
}