Storing XML data by using the IMS Universal JDBC driver
You can use the IMS Universal JDBC driver to store XML data into an IMS database through an SQL INSERT statement.
To store XML data in your IMS Universal JDBC driver application:
Procedure
The following code sample shows how to insert XML data into the Hospital database.
package uxml.samples;
import java.io.*;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.PreparedStatement;
import com.ibm.ims.jdbc.IMSDataSource;
public class StoreXMLSamples{
public static void main(String argv[]) throws SQLException,IOException {
IMSDataSource ds = new IMSDataSource();
ds.setDatabaseName("class://uxml.samples.BMP255NewSyntaxDatabaseView");
ds.setDatastoreName("IMS1");
ds.setDatastoreServer("yourhost.yourdomain.com");
ds.setPortNumber(5555);
ds.setDriverType(IMSDataSource.DRIVER_TYPE_4);
ds.setUser("myUserID");
ds.setPassword("myPass");
// Specify file path of XML schema
System.setProperty("http://www.ibm.com/ims/schema-resolver/file/path",
"uxml/samples");
Connection conn = null;
try {
conn = ds.getConnection();
Statement st = conn.createStatement();
String doc = "hospwashington.xml";
StoreXMLSamples storeSample = new StoreXMLSamples();
InputStream fileStream =
storeSample.getClass().getResourceAsStream(doc);
if (fileStream == null) {
throw new FileNotFoundException("Insert Document: '" +
doc + "' was not found in classpath");
}
// Convert XML document from ASCII to Unicode
InputStreamReader fileReader =
new InputStreamReader(fileStream, "ASCII");
PreparedStatement ps =
conn.prepareStatement("INSERT INTO pcb01.HOSPITAL" +
" (hospxml) VALUES (?)");
ps.setCharacterStream(1, fileReader, -1);
int rows = ps.executeUpdate();
System.out.println("Inserted");
conn.commit();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
if (!conn.isClosed()) {
conn.rollback();
conn.close();
}
}
}
}