Interstage Shunsaku Data Manager Application Development Guide - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX -
|
Contents
Index

|
F.2.1 Adding Data
The following example shows how the Java APIs are used to add data.
Data to be added
'I want to add an item of information about an Adelaide hotel (Hotel 9).'
Assemble the data to be added then add the data.
An Example of Using the APIs
The following is a sample program using the Java APIs.
import com.fujitsu.shun.ShunConnection;
import com.fujitsu.shun.ShunPreparedStatement;
import com.fujitsu.shun.common.ShunException;
/*** Add specified data ***/
public class JavaAPISample6 {
public static void main(String[] args) {
ShunConnection con = null;
ShunPreparedStatement pstmt = null;
try {
// Create ShunConnection object
con = new ShunConnection("DirSvr1", 33101);
// Create ShunPreparedStatement for adding data
pstmt = con.prepareInsert();
// Create data to be added
String addData =
"<document>"
+ " <base>"
+ " <name>Hotel 9</name>"
+ " <city>Adelaide</city>"
+ " <address>Belair, Adelaide</address>"
+ " <detail>http://xxxxx.com.au</detail>"
+ " <price>150</price>"
+ " </base>"
+ " <information>"
+ " <date>2006/07/18</date>"
+ " </information>"
+ "<note>No-smoking room with en-suite bathroom and toilet available, 5 minutes' walk to subway station XX</note>"
+ "</document>";
// Add data
pstmt.add(addData);
// Execute data addition
pstmt.executeInsert();
System.out.println("Addition complete");
pstmt.close();
con.close();
}
// Processing to perform if an error occurs while the application is running
catch (ShunException ex) {
int errorLevel = ex.getErrLevel();
switch( errorLevel ) {
case ShunException.SHUN_ERROR :
System.out.println("Error level :SHUN_ERROR");
break;
case ShunException.SHUN_ERROR_CONNECTION_TERMINATED :
System.out.println("Error level :SHUN_ERROR_CONNECTION_TERMINATED");
break;
}
System.out.println("Error message:" + ex.getMessage());
ex.printStackTrace();
}
catch (Exception ex) {
System.out.println("Error message:" + 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("Error level :SHUN_ERROR");
break;
case ShunException.SHUN_ERROR_CONNECTION_TERMINATED :
System.out.println("Error level :SHUN_ERROR_CONNECTION_TERMINATED");
break;
}
System.out.println("Error message:" + 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("Error level :SHUN_ERROR");
break;
case ShunException.SHUN_ERROR_CONNECTION_TERMINATED :
System.out.println("Error level :SHUN_ERROR_CONNECTION_TERMINATED");
break;
}
System.out.println("Error message:" + ex.getMessage());
ex.printStackTrace();
}
}
}
} |
Execution Results
All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006