Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / January 2007

Tip: Looking for answers? Try searching our database.

Java UDT

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
eviewcs - 29 Jan 2007 09:20 GMT
Hello I am a newbie in DB2.

I am trying out the Mapping Java definitions to SQL on UDT from the
article "DB2's object-relational highlights: Store and invoke
structured type objects" by Kathryn Zeidenstein.
The url is :
http://www-128.ibm.com/developerworks/db2/library/techarticle/
zeidenstein/0109zeidenstein.html#xforms

In the article , it is said that the use of Java classes to define SQL
types is possible.
When i created the example on the sql side, the following exception is
thrown :
com.ibm.db2.jcc.c.SqlException: The name "TEST_T1" has the wrong
number of qualifiers.

Following is the source that I have created :

On the java side :

package myProject;

import java.sql.SQLData;
import java.sql.SQLException;
import java.sql.SQLInput;
import java.sql.SQLOutput;

public class TestUdt implements SQLData {

    public String strVal;
    public int intVal;
    public char charVal;

    public static final String TYPE_NAME = "TEST_T";

    /**
    * constructor to match the type in DB2
    * @param strVal
    * @param intVal
    * @param charVal
    */
    public TestUdt(String strVal, int intVal, char charVal) {
        this.strVal = strVal;
        this.intVal = intVal;
        this.charVal = charVal;
    }

    /**
    * readSQL()
    * being called by JDBC driver to populates this object
    * with data read from the database.
    **/
    public void readSQL(SQLInput in, String type)
   throws SQLException {
        strVal = in.readString();
        intVal = in.readInt();
        charVal = in.readString().charAt(0);
    }

    /**
    * Returns the fully-qualified
    * name of the SQL user-defined type that this object represents (in
DB2).
    */
    public String getSQLTypeName() throws SQLException {
        return TYPE_NAME;
    }

    /**
    * writeSQL()
    * being called by JDBC driver to write this object
    * to the given SQL data.
    **/
    public void writeSQL(SQLOutput out)
   throws SQLException {
        out.writeString(strVal);
        out.writeInt(intVal);
        out.writeString(String.valueOf(charVal));
    }

    /**
    * test method in UDT
    * @return strVal + intVal + charVal
    */
    public String printAllAttr() {
        return strVal + "," + Integer.toString(intVal) + "," +
String.valueOf(charVal);
    }

    /**
    * test method in UDT
    * @param newStr
    */
    public void changestring(String newStr) {
        strVal = newStr;
    }
}

On the sql side :

CREATE TYPE EVIE.TEST_T1
     EXTERNAL NAME 'EVIE.TESTUDT:myProject.TestUdt'
     LANGUAGE JAVA
     USING SQLDATA
     AS( STRVAL    VARCHAR(100),
         INTVAL    INTEGER,
         CHARVAL   CHAR(20))
CONSTRUCTOR METHOD EVIE.TEST_T1 (s VARCHAR(10),  d INT, c CHAR(20))
   RETURNS EVIE.TEST_T1
    SELF AS RESULT
EXTERNAL NAME 'EVIE.TESTUDT:myProject.TestUdt';

I have compiled and archived myProject.TestUdt to a jar , and
installed it using sqlj.install_jar command namely TESTUDT.jar under
user EVIE in my DB2.

Can anybody advice me on this matter?
Knut Stolze - 29 Jan 2007 19:22 GMT
> Hello I am a newbie in DB2.
>
[quoted text clipped - 113 lines]
>
> Can anybody advice me on this matter?

I would remove the "EVIE." part in the external name clauses.  In front of
the colon goes the name of the JAR.  After the colon comes the classname
and finally the method name.

Signature

Knut Stolze
DB2 z/OS Utilities Development
IBM Germany

eviewcs - 30 Jan 2007 01:17 GMT
> > Hello I am a newbie in DB2.
>
[quoted text clipped - 120 lines]
> DB2 z/OS Utilities Development
> IBM Germany

I removed the "EVIE." part on external name but same exception is
still being thrown :(
The exception is : com.ibm.db2.jcc.c.SqlException: The name "TEST_T1"
has the wrong number of qualifiers.
What is the meaning of "qualifiers" in the exception?
Knut Stolze - 30 Jan 2007 20:19 GMT
> Hello I am a newbie in DB2.
>
[quoted text clipped - 36 lines]
> SELF AS RESULT
> EXTERNAL NAME 'EVIE.TESTUDT:myProject.TestUdt';

I have question on this statement of yours: DB2 does not support this syntax
(see here:
http://publib.boulder.ibm.com/infocenter/db2luw/v8/topic/com.ibm.db2.udb.doc/adm
in/r0000933.htm
).
Thus, I'm a but surprised that you didn't get a syntax error.  Referring to
the article that you cited, I guess this may be stuff that has been
withdrawn in V8 (and did work in V7).  So I would suggest that you don't
use this functionality.

As for the error message.  My take on this would be that the first EXTERNAL
NAME clause receives the class name.  All additional EXTERNAL NAME clauses
specify the method within that class only.  So this may be correct:

CREATE TYPE EVIE.TEST_T1
  EXTERNAL NAME 'EVIE.TESTUDT:myProject.TestUdt'
  LANGUAGE JAVA
  USING SQLDATA
  AS( STRVAL   VARCHAR(100),
      INTVAL   INTEGER,
      CHARVAL   CHAR(20))
 CONSTRUCTOR METHOD EVIE.TEST_T1 (s VARCHAR(10),  d INT, c CHAR(20))
    RETURNS EVIE.TEST_T1
    SELF AS RESULT
    EXTERNAL NAME 'TestUdt';

Signature

Knut Stolze
DB2 z/OS Utilities Development
IBM Germany

eviewcs - 31 Jan 2007 02:18 GMT
> > Hello I am a newbie in DB2.
>
[quoted text clipped - 64 lines]
> DB2 z/OS Utilities Development
> IBM Germany

I've just found out that the integration with java on structured type
as introduced in the article was actually a feature not implemented in
DB2. Seems to me that the codes provided in the article was not tested
hence the various syntax errors.
It got me a little frustfrated because of the time I spent to try make
the codes work as I believed that IBM articles should provide reliable
information *frown*.

Thanks anyway.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.