Troubleshooting Case1b

Go back to: Code Samples
PreparedStatement getPhotoStmt = con.prepareStatement(
    "SELECT photo FROM FBI_most_wanted " +
    "WHERE state=? AND fname=? AND lname=? AND crimes=? " +
    "AND convictions=? AND laddress=?");
 
PreparedStatement pstmt = con.prepareStatement(
    "SELECT fname, lname, crimes, convictions, laddress " +
    "FROM FBI_most_wanted WHERE state=?");
 
pstmt.setString(1, "NC");
ResultSet rs = pstmt.executeQuery ();
 
// Display all rows
while (rs.next()) {
    String fname = rs.getString(1);
    String lname = rs.getString(2);
    String crimes = rs.getString(3);
    String convictions = rs.getString(4);
    String laddress = rs.getString(5);
 
    if (isPersonOfInterest(fname, lname, crimes, convictions, 
        laddress)) {
        getPhotoStmt.setString(1, "NC");
        getPhotoStmt.setString(2, fname);
        getPhotoStmt.setString(3, lname);
        getPhotoStmt.setString(4, crimes);
        getPhotoStmt.setString(5, convictions);
        getPhotoStmt.setString(6, laddress);
        ResultSet rs2 = getPhotoStmt.executeQuery();
        if (rs2.next()) {
            Object photo = rs2.getObject(1);
            displayPhoto(photo);
        }
        rs2.close();
    }
}
rs.close();




Like what you see? Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis

Book Content Copyright © 2009 by Prentice Hall PTR. All rights reserved. | Corporate Sponsor DataDirect Technologies.