Java Reference
In-Depth Information
L ISTING 7.5 Continued
// Create the statement
Statement statement = con.createStatement();
// Use the created statement to SELECT the DATA
// FROM the Titles Table.
// In this instance we are searching for an exact match.
// If you were to deploy this to a production site, you
// might want to use a “LIKE” clause instead of WHERE.
ResultSet rs = statement.executeQuery(“SELECT * “ +
“FROM Titles WHERE rating = '“ +
search_string + “'“);
7
// Iterate over the ResultSet
while ( rs.next() ) {
out.println(“<tr>”);
// get the id, which is an int
out.println(“<td>” + rs.getInt(“title_id”) + “</td>”);
// get the name, which is a String
out.println(“<td>” + rs.getString(“title_name”) + “</td>”);
// get the rating, which is a String
out.println(“<td>” + rs.getString(“rating”) + “</td>”);
// get the price, which is a Float
out.println(“<td>” + rs.getFloat(“price”) + “</td>”);
// get the Quantity, which is a Integer
out.println(“<td>” + rs.getInt(“quantity”) + “</td>”);
// get the Type, which is a Integer
out.println(“<td>” + rs.getInt(“type_id”) + “</td>”);
// get the Category, which is a Integer
out.println(“<td>” + rs.getInt(“category_id”) + “</td>”);
out.println(“</tr>”);
}
// Close the ResultSet
rs.close();
out.println(“</table>”);
 
Search WWH ::




Custom Search