JDBC Driver for Microsoft Exchange

Build 23.0.8839

JNDI

JNDI でのコネクションプーリング

Java Naming and Directory Service(JNDI)は、分散アプリケーションがサービスを検索できるようにするAPI です。JNDI を使用すると、コネクションプールを簡単に設定できます。

JNDI を使用してコネクションプールを設定するには、以下のサンプルコードに示すように、JNDI ファイルシステムサービスプロバイダーを初期化する必要があります。このサンプルを実行するには、クラスパスにfscontext.jar ファイルとproviderutil.jar ファイルを追加する必要があります。これらのファイルは、Oracle Java Archive からダウンロードできます。Java SE セクションで、[Java Platform Technologies]->[Java Naming and Directory Interface]を選択します。

 
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:///tmp");

Context ctx = new InitialContext(env); 
DataSource ds = null;
Connection conn = null;
次のコードは、ExchangeDataSource をJNDI ネーミングサービスに登録し、サービスからDataSource のインスタンスを取得し、インスタンスからプールされた接続を作成します。
try {
  ExchangeConnectionPoolDataSource exchangeDataSource = new ExchangeConnectionPoolDataSource();
  exchangeDataSource.setURL("jdbc:exchange:UseConnectionPooling=true;User='myUser@mydomain.onmicrosoft.com';Password='myPassword';Server='https://outlook.office365.com/EWS/Exchange.asmx';Platform='Exchange_Online';Schema='EWS';");
  ctx.bind("jdbc/exchange", exchangeDataSource);
  ds = (DataSource) ctx.lookup("jdbc/exchange");

  conn = ds.getConnection();
  Statement stat = conn.createStatement();
  boolean ret = stat.execute("SELECT 1");
  ResultSet rs=stat.getResultSet(); 
} catch(Exception ex) { } finally {
  if(conn != null) conn.close();
}

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 23.0.8839