Insert data
You can insert an opaque type as either its original type
or its cast type. The following example shows how to insert opaque
data using the original type:
String s = "insert into charattr_tab (int_col, charattr_col) values (?, ?)"; System.out.println(s); pstmt = conn.prepareStatement(s); ... charattrUDT charattr = new charattrUDT(); charattr.chr1 = "a"; charattr.bold = true; charattr.fontsize = (short)1; pstmt.setInt(1, 1); System.out.println("setInt...ok"); pstmt.setObject(2, charattr); System.out.println("setObject(charattrUDT)...ok"); pstmt.executeUpdate();
If a casting function is defined, and you would like to
insert data as the casting type instead of the original type, you
must call the setXXX() method that corresponds
to the casting type. For example, if you have defined a function casting
CHAR or LVARCHAR to a charattrUDT column, you can use the setString() method
to insert data, as follows:
// Insert into UDT column using setString(int,String) and Java String object. String s = "insert into charattr_tab " + "(decimal_col, date_col, charattr_col, float_col) " + "values (?,?,?,?)"; writeOutputFile(s); PreparedStatement pstmt = myConn.prepareStatement(s); ... String strObj = "(A, f, 18)"; pstmt.setString(3, strObj); ...