<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.sql.*" %>

<%
// Kiem tra da login hay chua ?
if (session == null ||
	session.getAttribute("Username") == null ||
	((String)session.getAttribute("Username")).equals("") )
{
	response.sendRedirect("Login.jsp"); // Dang nhap lai
}

%>

<html>
<head>
<title>
SearchNoBean
</title>
</head>
<body bgcolor="#ffffff">
<h1>Kết quả tìm kiếm: </h1>
<table >
	<th>Mã số KH </th>
	<th>Họ và tên </th>
	<th>Số ĐT </th>
	<th>Địa chỉ </th>

<%
	String strTentb = request.getParameter("tentb"); // Lay gia tri tentb tu FORM
	String strSodt = request.getParameter("sodt"); // Lay gia tri sodt tu FORM

	// Xay dung cau SELECT
		String newSQL = "SELECT * FROM CUSTOMERS ";
		if (strTentb != null && strTentb.length() > 0) {
			newSQL += " WHERE Tentb Like '%" + strTentb + "%'";
		}

		// Tao ket noi den Database
		java.sql.Connection con = null;
		java.sql.Statement stmt = null;
		java.sql.ResultSet rs = null;
		try {
			String conStr = "jdbc:odbc:DanhBaDB";

			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			con = DriverManager.getConnection(conStr, "", "" );

			// Tao mot Statement
			stmt = con.createStatement();
			rs = stmt.executeQuery( newSQL );

			if (rs != null  ) {
				int i = 0;
				for (i = 0 ; rs.next() ; i++ ) {
%>

					<tr>
					<td> <%= rs.getString("Tentb") %> </td>
					<td> <%= rs.getString("Maso") %> </td>
					<td> <%= rs.getString("Sodt") %> </td>
					</tr>

<%
				}
				rs.close();

				// out.println("Tim thay so ket qua la: " + i);

			}else {
				// out.println("Khong tim thay");
			}

			// out.println("</pre>");
			con.close();
		}catch(Exception ex) {
			System.out.println("Exception: " + ex );
		}

%>


</table>
</body>
</html>
