Java data access

Page 316

Chapter 17: Building Data−centric Web Applications if((orderByDir == null) || orderByDir.equals("")) { orderByDir = "asc"; } // Compose the query statement. String query = "SELECT Employees.SSN, Employees.Name, " "Employees.Salary, " + "Employees.Hiredate, Location.Location " + "FROM Location " + "INNER JOIN Employees " + "ON Location.Loc_Id = Employees.Loc_Id " + "ORDER BY " + orderBy + " " + orderByDir + ";"; // Execute the query. ResultSet rs = dbBean.query(query); %> <table border="1"> <tr> <% String fields[] = {"SSN", "Name", "Salary", "Hiredate", "Location"}; for(int i = 0; i < fields.length; i++) { String field = fields[i]; %> <th> <%−−Workaround for Netscape Navigator so that the up arrow graphic aligns with the header−−%> <% if(clientIsNetscapeNavigator){%> <%} %> <a href="AllEmployeesBean.jsp?sort=<%= field %>&sortdir=asc"> <img border=0 align="absmiddle" src="up12.gif" alt="Sort by <%= field %> in ascending order"> </a> <%= field %> <a href="AllEmployeesBean.jsp?sort=<%= field %>&sortdir=desc"> <img border=0 align="absmiddle" src="down12.gif" alt="Sort by <%= field %> in descending order"> </a> </th> <% } %> <th>Action</th> </tr> <% // Add one select option for each employee name returned in the // result set. while(rs.next()) { long employeeSSN = rs.getLong("SSN"); String employeeName = rs.getString("Name"); long employeeSalary = rs.getLong("Salary"); Date employeeHiredate = rs.getDate("Hiredate"); String employeeLocation = rs.getString("Location"); %> <tr> <td align="right"><%= employeeSSN%></td> <td><%= employeeName%></td> <td align="right"><%= employeeSalary%>.00</td> <td align="right"><%= employeeHiredate%></td> <td><%= employeeLocation%></td> <td> <a href="EditEmployeeBean.jsp?SSN= <%= employeeSSN %>">Edit</a>

304


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.