| Interstage Shunsaku Data Manager アプリケーション開発ガイド - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX共通 - |
目次
索引
![]()
|
| 付録F Java サンプルプログラム | > F.3 拡張的なアプリケーション |
ダイレクトアクセスキーを使用してデータを削除する場合のJava APIの使用例を示します。
<course>
<id>0001</id>
<name>Business negotiation</name>
<instructor>
<first-name>Max</first-name>
<last-name>cameron</last-name>
</instructor>
<capacity>40</capacity>
<current-auditors>30</current-auditors>
</course> |
key /course/id/text() |
以下にJava APIを使用したプログラミング例を示します。
import com.fujitsu.shun.ShunConnection;
import com.fujitsu.shun.ShunPreparedKey;
import com.fujitsu.shun.common.ShunException;
/*** ダイレクトアクセスキーを使用してデータを削除します ***/
public class DirectAccessSample3 {
public static void main(String[] args) {
ShunConnection con = null;
ShunPreparedKey keystmt = null;
try {
//ダイレクトアクセスキー名
String sCoursKeyName = "key";
//ダイレクトアクセスキー
String key = "0001";
// ShunConnectionオブジェクトを作成
// 接続先のホスト名:DirSvr1、
// ポート番号:33101、
// Shunsaku File名:shunsakuFile1の場合
con = new ShunConnection("DirSvr1", 33101, "shunsakuFile1");
//削除用のShunPreparedKeyオブジェクトを作成
keystmt = con.prepareDeleteKey(sCoursKeyName);
//削除したいデータのダイレクトアクセスキーを追加
keystmt.add(key);
//コース情報の削除
keystmt.deleteByKey();
System.out.println("削除終了");
keystmt.close();
con.close();
}
// アプリケーション実行時にエラーが発生した場合の処理
catch (ShunException ex) {
int errorLevel = ex.getErrLevel();
switch (errorLevel) {
case ShunException.SHUN_ERROR:
System.out.println("エラーレベル :SHUN_ERROR");
break;
case ShunException.SHUN_ERROR_CONNECTION_TERMINATED:
System.out.println("エラーレベル :SHUN_ERROR_CONNECTION_TERMINATED");
break;
}
System.out.println("エラーメッセージ:" + ex.getMessage());
ex.printStackTrace();
}
catch (Exception ex) {
System.out.println("エラーメッセージ:" + ex.getMessage());
ex.printStackTrace();
}
// エラーが発生した場合の回収処理
finally {
try {
if(keystmt != null) keystmt.close();
}
catch (ShunException ex) {
int errorLevel = ex.getErrLevel();
switch (errorLevel) {
case ShunException.SHUN_ERROR:
System.out.println("エラーレベル :SHUN_ERROR");
break;
case ShunException.SHUN_ERROR_CONNECTION_TERMINATED:
System.out.println("エラーレベル :SHUN_ERROR_CONNECTION_TERMINATED");
break;
}
System.out.println("エラーメッセージ:" + ex.getMessage());
ex.printStackTrace();
}
try {
if(con != null) con.close();
}
catch (ShunException ex) {
int errorLevel = ex.getErrLevel();
switch (errorLevel) {
case ShunException.SHUN_ERROR:
System.out.println("エラーレベル :SHUN_ERROR");
break;
case ShunException.SHUN_ERROR_CONNECTION_TERMINATED:
System.out.println("エラーレベル :SHUN_ERROR_CONNECTION_TERMINATED");
break;
}
System.out.println("エラーメッセージ:" + ex.getMessage());
ex.printStackTrace();
}
}
}
} |
削除終了 |
目次
索引
![]()
|