( large object locator datablade ) lld_locator column & JDBC
Posted in 2005
Topics: Storage & Space Management, Error Codes & Troubleshooting, Connectivity: ODBC / JDBC / .NET, Connectivity: ESQL/C, 4GL & Embedded SQL, Data Types & Schema Design, Java & JDBC Development
I'm trying to write to an lld_locator column via JDBC. I believe the way to do this is to wrap this type in a class which extends SQLData. However I can't seem to quite get it to work correctly. It's a bit confusing since the lld_locator type: lld_locator { lo_protocol char(18) lo_pointer informix.lld_lob lo_location informix.lvarchar } also uses this user defined subtype typedef struct { ifx_lo_t lo; int type; } lld_lob_t; lo is a pointer to the location of the smart large object. type is the type of the object. For an object containing binary data, set type to LLD_BLOB; for an object containing character data,set type to LLD_CLOB. I get an exception in writeSQL() when I try and write out the int lob type. Here is the stack trace: java.sql.SQLException: Type requested (int) doesn't match row type information (udt fixed) type. at com.informix.jdbc.IfxComplex.a(IfxComplex.java:854) at com.informix.jdbc.IfxComplexOutput.c(IfxComplexOutput.java:3348) at com.informix.jdbc.IfxComplexOutput.b(IfxComplexOutput.java:3279) at com.informix.jdbc.IfxComplexOutput.a(IfxComplexOutput.java:250) at com.informix.jdbc.IfxComplexOutput.writeInt(IfxComplexOutput.java:405) at com.cnn.broadcast.msmm.jdbc.LLDLocator.writeSQL(LLDLocator.java:86) at com.informix.jdbc.IfxComplexOutput.b(IfxComplexOutput.java:1190) at com.informix.jdbc.IfxRow.fromObject(IfxRow.java:141) at com.informix.jdbc.IfxValue.a(IfxValue.java:1227) at com.informix.jdbc.IfxValue.a(IfxValue.java:452) at com.informix.jdbc.IfxValue.a(IfxValue.java:434) at com.informix.jdbc.IfxPreparedStatement.setObject(IfxPreparedStatement.java:2504) at com.cnn.broadcast.msmm.dao.AssetDAO.insertKeyframes(AssetDAO.java:559) at com.cnn.broadcast.msmm.unittest.MessageUnitTest.testBuildKeyframeMeta(MessageUnitTest.java:153) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) byte[] buffer = new byte[200]; IfxLobDescriptor loDesc = new IfxLobDescriptor(connection); IfxLocator loPtr = new IfxLocator(); IfxSmartBlob smb = new IfxSmartBlob(connection); // Create a smart large object in server int loFd = smb.IfxLoCreate(loDesc, IfxSmartBlob.LO_RDWR, loPtr); System.out.println("A smart-blob has been created "); int n = smb.IfxLoWrite(loFd, buffer); smb.IfxLoClose(loFd); System.out.println("Wrote: " + n +" bytes into it"); //IfxBblob ifxblob = new IfxBblob(loPtr); log.debug("executing: " + newKeyframeStmt); keyframeStmt.setLong(1, chunkId); keyframeStmt.setInt(2, timebased.getSequenceNum()); keyframeStmt.setObject(3, new LLDLocator(loPtr)); keyframeStmt.setString(4, timebased.getPartitioDescription()); keyframeStmt.executeUpdate(); Below is the code that writes the column out: public class LLDLocator implements SQLData { public String lo_protocol; // next two are for lld_lob public IfxLocator smart_locator; public int lld_lob_type; public String lo_location; private String sql_type; /** * * values for the type field of lld_lob_t -- from /informix/930hc5x4/extend/LLD.1.20.HC2/incl/lldsapi.h * * #define LLD_BLOB 0 * #define LLD_CLOB 1 * */ protected static final int LLD_BLOB = 0; protected static final int LLD_CLOB = 1; public LLDLocator(IfxLocator locator) { this.lo_protocol = "IFX_BLOB"; this.smart_locator = locator; this.lld_lob_type = LLD_BLOB; this.lo_location = "NULL"; // the large object datablade says to specify NULL // if using a smart large object. } public String getSQLTypeName() { return "lld_locator"; } public void readSQL (SQLInput stream, String type) throws SQLException { sql_type = type; lo_protocol = stream.readString(); //lo_pointer = (IfxSmartBlob)stream.readObject(); lo_location = stream.readString(); } public void writeSQL (SQLOutput stream) throws SQLException { stream.writeString(lo_protocol); stream.writeBytes(smart_locator.toBytes()); stream.writeInt(lld_lob_type); stream.writeString(lo_location); } }