String id = cust_id.getText();
try {
PreparedStatement prepstmt;
boolean found = false;
prepstmt = theConn.prepareStatement
("select custName, CustAddr from tCust where custId = ?");
prepstmt.setString(1, id);
ResultSet rs;
rs = prepstmt.executeQuery();
found = rs.next();
if (found)
System.out.println(rs.getString(1));
else
System.out.println("Customer " + id + " not found!");
prepstmt.close();
}
catch (Exception e) {
e.printStackTrace();
}String name = cust_name.getText();
try {
Statement stmt;
String sql;
sql = "select custName from tCust where custName = "
+= "'" + name + "'";
stmt = theConn.createStatement();
ResultSet rs;
rs = stmt.executeQuery();
while (rs.next()) {
System.out.println(rs.getString("custName"));
}
rs.close();
stmt.close();
}
catch (Exception e) {
e.printStackTrace();
}Thanks to Lawrence Angrave for the warning.
Written and compiled by Réal Gagnon ©1998-2005
[ home ]