JDBC Type 4 Driver Programmer's Reference for SQL/MX Release 3.1 (H06.23+, J06.12+)

+ length + " of file " + args[1]);
try {
Class.forName("com.tandem.t4jdbc.SQLMXDriver");
start = System.currentTimeMillis();
//url should be of the form:
// jdbc:t4sqlmx://ip_address|machine_name:port_number/:”
String url = “jdbc:t4sqlmx://mymachine:6000/:”;
conn1 = DriverManager.getConnection(url);
System.out.println("Cleaning up test tables...");
Statement stmt0 = conn1.createStatement();
stmt0.execute("delete from clobdatatbl");
stmt0.execute("delete from clobbase");
conn1.setAutoCommit(false);
}
catch (Exception e1) {
e1.printStackTrace();
}
// PreparedStatement interface example - This technique
// is suitable if the LOB data is already on the NonStop
// system disk.
try {
System.out.println("PreparedStatement interface
LOB insert...");
String stmtSource1 = "insert into clobbase
values (?,?)";
PreparedStatement stmt1
= conn1.prepareStatement(stmtSource1);
stmt1.setInt(1,recKey);
stmt1.setAsciiStream(2,clobFs,length);
stmt1.executeUpdate();
conn1.commit();
}
catch (SQLException e) {
e.printStackTrace();
SQLException next = e;
do {
System.out.println("Messge : " + e.getMessage());
System.out.println("Error Code : " + e.getErrorCode());
System.out.println("SQLState : " + e.getSQLState());
} while ((next = next.getNextException()) != null);
}
// Clob interface example - This technique is suitable when
// the LOB data is already in the app, such as having been
// transferred in a msgbuf.
try {
// insert a second base table row with an empty LOB column
System.out.println("CLOB interface EMPTY LOB insert...");
String stmtSource2 = "insert into clobbase
values (?,EMPTY_CLOB())";
PreparedStatement stmt2
= conn1.prepareStatement(stmtSource2);
stmt2.setInt(1,recKey+1);
stmt2.executeUpdate();
Clob clob = null;
System.out.println("Obtaining CLOB data to
update (EMPTY in this case)...");
PreparedStatement stmt3
= conn1.prepareStatement("select col2
from clobbase where col1 = ? for update");
stmt3.setInt(1,recKey+1);
ResultSet rs = stmt3.executeQuery();
if (rs.next()) clob = rs.getClob(1); // has to be there
// else the base table insert fails
System.out.println("Writing data to previously empty CLOB...");
OutputStream os = clob.setAsciiStream(1);
byte[] bData = k.getBytes();
os.write(bData);
os.close();
conn1.commit();
}
catch (SQLException e) {
e.printStackTrace();
SQLException next = e;
do {
System.out.println("Messge : " + e.getMessage());
System.out.println("Vendor Code : " + e.getErrorCode());
System.out.println("SQLState : " + e.getSQLState());
} while ((next = next.getNextException()) != null);
}
} // main
} // class
Sample Program Accessing BLOB Data
This sample program shows the use of both the Blob interface and the PreparedStatement interface to take a byte variable and put the variable's
value into a base table that has a
BLOB column.
// LOB operations may be performed through the Blob, or
// PreparedStatement interface. This program shows examples of
// using both interfaces taking a byte[] variable and putting
// it into the cat.sch.blobtiff table.
//
// The LOB base table for this example is created as: