Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

暗黙結合の使用

以下のメソッドは、Caché の暗黙結合構文を使用してクエリを定義し、そのクエリをデータベースに対して実行します。クエリは、以下の条件を満たす、すべての PhoneNumber 行の Number 値を選択します。

  • PhoneNumberType の値が type です。

  • Contact 値で参照される Contact テーブルの行で、Name の値が 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