Interstage Shunsaku Data Manager アプリケーション開発ガイド - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX共通 -
|
目次
索引

|
F.2.1 データを追加する
データを追加する場合のJava APIの使用例を示します。
■追加するデータ
「神奈川のホテル情報(ホテル9の情報)を1件追加したい。」
追加したいデータを組み立て、データを追加します。
■APIの使用例
以下にJava APIを使用したプログラミング例を示します。
import com.fujitsu.shun.ShunConnection;
import com.fujitsu.shun.ShunPreparedStatement;
import com.fujitsu.shun.common.ShunException;
/*** 指定されたデータを追加します ***/
public class JavaAPISample6 {
public static void main(String[] args) {
ShunConnection con = null;
ShunPreparedStatement pstmt = null;
try {
// ShunConnectionオブジェクトを作成
con = new ShunConnection("DirSvr1", 33101);
// データ追加用にShunPreparedStatementオブジェクトを作成
pstmt = con.prepareInsert();
// 追加するデータを作成
String addData =
"<document>"
+ " <base>"
+ " <name>ホテル9</name>"
+ " <prefecture>新横浜</prefecture>"
+ " <address>神奈川県横浜市神奈川区</address>"
+ " <detail>http://xxxxx.co.jp</detail>"
+ " <price>6000</price>"
+ " </base>"
+ " <information>"
+ " <date>2006年07月18日</date>"
+ " </information>"
+ "<note>バス付 トイレ付 禁煙ルーム選択可 地下鉄 △△駅徒歩05分</note>"
+ "</document>";
// データを追加
pstmt.add(addData);
// データ追加を実行
pstmt.executeInsert();
System.out.println("追加終了");
pstmt.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 (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 (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();
}
}
}
} |
■実行結果
All Rights Reserved, Copyright(C) 富士通株式会社 2006