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();
}
}
}
} |