JDBC Type 4 Driver Programmer's Reference for SQL/MX Release 3.2.1

numBytes = iXstream.available();
if (args.length == 3)
numBytes = Integer.parseInt(args[2]);
recKey = Integer.parseInt(args[0]);
System.out.println("Key: " + recKey +"; Using "
+ numBytes + " 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:port/:";
String user ="UserName";
String password="password";
conn1 = DriverManager.getConnection(url,user,password);
System.out.println("Cleaning up test tables...");
Statement stmt0 = conn1.createStatement();
stmt0.execute("delete from blobdatatbl");
stmt0.execute("delete from blobtiff");
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 blobtiff values (?,?)";
PreparedStatement stmt1 = conn1.prepareStatement(stmtSource1);
stmt1.setInt(1,recKey);
stmt1.setBinaryStream(2,iXstream,numBytes);
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);
}
// Blob interface example - This technique is suitable when
// the LOB data is already in the app, such as having been
// transfered in a msgbuf.
try {
// insert a second base table row with empty LOB column
System.out.println("BLOB interface LOB insert...");
String stmtSource2 = "insert into blobtiff
values (?,EMPTY_BLOB())";
PreparedStatement stmt2 = conn1.prepareStatement(stmtSource2);
stmt2.setInt(1,recKey+1);
stmt2.executeUpdate();
Blob tiff = null;
Sample Program Accessing BLOB Data 115