Skip to main content

Using Implicit Join

The following method defines a query using the Caché implicit join syntax and executes it against the database. The query selects the value of Number for all PhoneNumber rows that meet the following criteria:

  • The value of PhoneNumberType is type.

  • The row of the Contact table referenced by the Contact value has the value name for Name.


public class JDBCExamples {
   public static void printPhoneNumbersByNameAndType
   (String name, String type) throws SQLException,
   ClassNotFoundException {
      Connection conn = JDBCExamples.createConnection();
      String sql =
      "SELECT Number FROM JavaTutorial.PhoneNumber "+
      "WHERE PhoneNumberType=? AND Contact->Name=?";
      PreparedStatement pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, type);
      pstmt.setString(2,name);
      ResultSet rs=pstmt.executeQuery();
      System.out.println("Name: " + name + " Type: " + type);
      while (rs.next()){
         System.out.println(rs.getString(1));
      }
      rs.close();
   }
}
FeedbackOpens in a new tab