JDBC Type 2 Driver 3.0 Programmer's Reference (SQL/MX 3.x)
// - need an Inputstream object that already has data
// - need a PreparedStatement object that contains the
// 'insert...' DML of the base table
// - ps.setAsciiStream() for the lob data
// - ps.executeupdate(); for the DML
//
// To run this example, issue the following:
// # java TestBLOB 1 TestBLOB.class 1000
//
import java.sql.*;
import java.io.*;
public class TestBLOB
{
public static void main (String[] args)
throws java.io.FileNotFoundException, java.io.IOException
{
int numBytes;
int recKey;
long start;
long end;
Connection conn1 = null;
// Set jdbcmx.blobTableName System Property. This property
// can also be added to the command line through
// "-Djdbcmx.blobTableName=...", or a
// java.util.Properties object can be used and passed to
// getConnection.
System.setProperty( "jdbcmx.blobTableName","cat.sch.blobdatatbl" );
if (args.length < 2) {
System.out.println("arg[0]=; arg[1]=file; arg[2]=");
return;
}
// byte array for the blob
byte[] whatever = new byte[5000];
for (int i=0; i<5000; i++) whatever[i] = 71; // "G"
String k = "K";
for (int i=0; i<5000; i++) k = k + "K";
System.out.println("string length = " + k.length());
java.io.ByteArrayInputStream iXstream
= new java.io.ByteArrayInputStream(whatever);
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.sqlmx.SQLMXDriver");
start = System.currentTimeMillis();
conn1 = DriverManager.getConnection("jdbc:sqlmx:");
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);










