import com.fujitsu.shun.ShunConnection;
import com.fujitsu.shun.ShunPreparedRecordID;
import com.fujitsu.shun.ShunPreparedStatement;
import com.fujitsu.shun.ShunResultSet;
import com.fujitsu.shun.common.ShunException;
/*** 指定されたデータを削除します ***/
public class JavaAPISample7 {
public static void main(String[] args) {
ShunConnection con = null;
ShunPreparedStatement pstmt = null;
ShunPreparedRecordID rid = null;
ShunResultSet rs = null;
try {
// 検索式
String sQuery = "/document/base/prefecture == '新横浜' AND /document/information/date == '2006年07月18日'";
// リターン式
String sReturn = "/document/base/name/text()";
// ShunConnectionオブジェクトを作成
con = new ShunConnection("DirSvr1", 33101);
// 検索式を指定し、ShunPreparedStatementオブジェクトを作成
pstmt = con.prepareSearch(sQuery, sReturn);
// ShunPreparedRecordIDオブジェクトを作成
rid = con.prepareDeleteRecordID();
//最大取得件数を設定
pstmt.setRequest(1, 30);
// 検索を実行し、ShunResultSetオブジェクトを作成
rs = pstmt.executeSearch();
// ホテル9のレコードIDを取得
while (rs.next()) {
if (rs.getString().equals("ホテル9")) {
rid.add(rs.getRecordID());
}
}
rs.close();
pstmt.close();
// レコードID取得に成功している場合、データを削除
if (0 < rid.getCount()) {
rid.deleteByRecordID();
System.out.println("削除終了");
}
rid.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 (rs != null)
rs.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 (pstmt != null)
pstmt.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 (rid != null)
rid.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();
}
}
}
} |