This code is probably totally wrong, but I'm in the learning process.
Im trying to figure out how to use multiple resultsets in 1 jsp page.
If I find the userID from Users table to match a userID in the usersType table, then the selectbox should be checked.
But it's not working until now.
Does somebody know an easier way to accomplish such a thing?
<%@page contentType="text/html; charset=iso-8859-1" language="java"%> <%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> <!DOCTYPE html> <html> <head> <title>Successfully Login</title> </head> <body bgcolor="#0099CC"> <div id="navigation"> <ul class="top-level"> <li><a href="success.jsp">Home</a></li> <li><a href="preferences.jsp">Preferences</a></li> <li><a href="recommendations.jsp">Recommendations</a></li> </ul> </div> <div id="wrapper"> <% Connection connection = null; Statement statement = null; Statement statement2 = null; ResultSet rs = null; ResultSet rs2 = null; ResultSet rs3 = null; Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance(); connection = DriverManager.getConnection("jdbc:derby://localhost:1527/recommendation;create=true;user=root;password=root"); statement = connection.createStatement(); statement2 = connection.createStatement(); String QueryString3 = "SELECT * FROM app.usersType WHERE userID = " + session.getAttribute("ID"); rs3 = statement2.executeQuery(QueryString3); %> <form name="frmPreferences" action="updateDatabase.jsp" method="post"> <table> <tr> <td>Do you like to watch movies or series? Or both?</td> </tr> <% String QueryString = "SELECT * FROM app.type"; rs = statement.executeQuery(QueryString); while(rs.next()){ if(rs.getInt(1) == rs3.getInt(2)){ %> <tr> <td><input type="checkbox" name="type" checked="checked" value="<%=rs.getString(2)%>" /><%=rs.getString(2)%></td> </tr> <% }else{ %> <tr> <td><input type="checkbox" name="type" value="<%=rs.getString(2)%>" /><%=rs.getString(2)%></td> </tr> <% } } rs.close(); %> <tr> <td> </td> </tr> <tr> <td>What genre do you like?</td> </tr> <% String QueryString2 = "SELECT * FROM app.genre"; rs2 = statement.executeQuery(QueryString2); while(rs2.next()){ %> <tr> <td><input type="checkbox" name="type" value="<%=rs2.getString(2)%>" /><%=rs2.getString(2)%></td> </tr> <% } %> <tr> <td> </td> </tr> <tr> <td><input type="submit" name="submit" value="Opslaan" /></td> </tr> </table> </form> <% // close all connections rs2.close(); statement.close(); connection.close(); %> <br /><br /> <a href="logout.jsp"><b>Logout</b></a> </div> </body> </html>