JavaSercer Pages DELETE FROM EmployeeProjects WHERE UserName = (Sbc web hosting)

JavaSercer Pages <%-- Delete the old project (if any) and insert the new ones --%> DELETE FROM EmployeeProjects WHERE UserName = ? INSERT INTO EmployeeProjects (UserName, ProjectName) VALUES(?, ?) The list of new projects selected by the user is sent to the updateprofile.jsp page in the projects request parameter. The projects bean property can therefore be updated using a action, setting the value to the result of the getParameterValues( ) method. As you may remember from Chapter 6, this method returns a String[] with all values for a parameter, and that’s also the data type defined for the projects property in the bean. One important item to note here. If the user deselects all checkboxes in the main.jsp page (Example 10.4), all projects should be removed from the bean as well. The problem here is that if no checkbox is selected, the projects request parameter is not sent at all. You must therefore use the type of request-time attribute value shown in Example 10.6, as opposed to using the param property, for the action. The action calls a property setter method only if it can find a corresponding parameter in the request. With no checkbox selected, the project’s property setter is not called and the previous value is not cleared. When you use the getParameterValues( ) method as a request-time attribute value, however, it works as it should: if no checkbox is selected the method returns null, clearing the property value; otherwise, it returns a String[] with the currently selected values, setting the property to the current list. The EmployeeProjects table (Table 10.1) contains one row per project for a user, with the username in the UserName column and the project name in the ProjectName column. The easiest way to update the database information is to first delete all existing rows, if any, and then insert rows for the new projects selected by the user. Since this requires execution of multiple SQL statements and all must either succeed or fail, the actions are placed within the body of an action. If the first action is successful but one of the others fails, the database information deleted by the first is restored so the database correctly reflects the state before the change. To delete the rows in the database, use the action with a SQL DELETE statement. A WHERE clause is used so that only the rows for the current user are deleted. Then the action is used to loop through all projects for the validUser bean. The body of the action contains an action that executes an INSERT statement for each project: INSERT INTO EmployeeProjects (UserName, ProjectName) VALUES(?, ?) web hosting jsp services

Comments are closed.