CData JDBC driver for Sage 200 は、Java Web アプリケーションに簡単に統合して利用することができます。本記事では、Jetty でドライバーをコネクションプールとして設定することで、効率的にSage 200 データをアプリケーションで連携利用する方法を説明します。Jetty でJNDI resource for Sage 200 を設定します。
DBC Driver for Sage 200 を JNDI Data Source として設定
次の手順で、Jetty とSage 200 の接続を確立します。
Jetty ベースでJNDI モジュールを有効化します。JNDI を有効化するコマンドラインは以下の通り:
java -jar ../start.jar --add-to-startd=jndi
- JDBC Driver の.jar ファイルと.lic ファイル(インストールディレクトリのlib フォルダ下)をcontext path のlib フォルダに配置します。
-
リソースおよびスコープを宣言します。リソース宣言で必要な接続プロパティを入力します。この例では、Sage 200 データソースをWeb アプリケーションのWEB-INF\jetty-env.xml レベルにdeclare しています。
<Configure id='sage200demo' class="org.eclipse.jetty.webapp.WebAppContext">
<New id="sage200demo" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg><Ref refid="sage200demo"/></Arg>
<Arg>jdbc/sage200db</Arg>
<Arg>
<New class="cdata.jdbc.sage200.Sage200Driver">
<Set name="url">jdbc:sage200:</Set>
<Set name="SubscriptionKey">12345</Set>
<Set name="Schema">StandardUK</Set>
</New>
</Arg>
</New>
</Configure>
- Schema: Determines which Sage 200 edition you are connecting to. Specify either StandardUK or ProfessionalUK.
- Subscription Key: Provides access to the APIs that are used to establish a connection. You will first need to log into the Sage 200 API website and subscribe to the API edition that matches your account. You can do so here: https://developer.columbus.sage.com/docs/services/api/uk. Afterwards, the subscription key may be found in your profile after logging into Sage 200.
-
Web xml でリソースを設定します:
jdbc/sage200db
javax.sql.DataSource
Container
-
これで、java:comp/env/jdbc/sage200db へのルックアップでSage 200 データにアクセスできます:
InitialContext ctx = new InitialContext();
DataSource mysage200 = (DataSource)ctx.lookup("java:comp/env/jdbc/sage200db");
Jetty にさらに統合
ここでは、シンプルなコネクションプーリングシナリオでのドライバーの接続について説明しました。追加での連携ケースについては、Jetty ドキュメントのWorking with Jetty JNDI 参照してください。