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é への接続 (java.sql.Connection または com.intersys.objects.Database のいずれかで表される) を構築すると、データベースを更新できます。以下のメソッドは、SQL の INSERT 操作をデータベースに対して実行します。PhoneNumber テーブルに新しい行を追加します。


public class JDBCExamples {
   public static void insertPhoneNumber(String contactId,
   String number, String type)throws SQLException, ClassNotFoundException{
      Connection conn = JDBCExamples.createConnection();
      String sql =
      "INSERT INTO JavaTutorial.PhoneNumber (Contact, Number, PhoneNumberType)"+
      "VALUES (?,?,?)";
      PreparedStatement pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, contactId);
      pstmt.setString(2, number);
      pstmt.setString(3, type);
      pstmt.executeUpdate();
   }
}

このメソッドでは、java.sql.PreparedStatement オブジェクトで表される、作成済み文を使用しています。これは、Connection クラスの prepareStatement メソッドを使用して生成されます。Caché Database クラスには、java.sql.PreparedStatement オブジェクトを返す prepareStatement も含まれています。

FeedbackOpens in a new tab