Java UDT

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eviewcs

    #1

    Java UDT

    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 :

    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.SQLDat a;
    import java.sql.SQLExc eption;
    import java.sql.SQLInp ut;
    import java.sql.SQLOut put;

    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(SQLInpu t 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(SQLOut put out)
    throws SQLException {
    out.writeString (strVal);
    out.writeInt(in tVal);
    out.writeString (String.valueOf (charVal));
    }

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

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


    On the sql side :

    CREATE TYPE EVIE.TEST_T1
    EXTERNAL NAME 'EVIE.TESTUDT:m yProject.TestUd t'
    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:m yProject.TestUd t';


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

    Can anybody advice me on this matter?

  • Knut Stolze

    #2
    Re: Java UDT

    eviewcs wrote:
    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 :

    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.SQLDat a;
    import java.sql.SQLExc eption;
    import java.sql.SQLInp ut;
    import java.sql.SQLOut put;
    >
    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(SQLInpu t 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(SQLOut put out)
    throws SQLException {
    out.writeString (strVal);
    out.writeInt(in tVal);
    out.writeString (String.valueOf (charVal));
    }
    >
    /**
    * test method in UDT
    * @return strVal + intVal + charVal
    */
    public String printAllAttr() {
    return strVal + "," + Integer.toStrin g(intVal) + "," +
    String.valueOf( charVal);
    }
    >
    /**
    * test method in UDT
    * @param newStr
    */
    public void changestring(St ring newStr) {
    strVal = newStr;
    }
    }
    >
    >
    On the sql side :
    >
    CREATE TYPE EVIE.TEST_T1
    EXTERNAL NAME 'EVIE.TESTUDT:m yProject.TestUd t'
    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:m yProject.TestUd t';
    >
    >
    I have compiled and archived myProject.TestU dt to a jar , and
    installed it using sqlj.install_ja r command namely TESTUDT.jar under
    user EVIE in my DB2.
    >
    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.

    --
    Knut Stolze
    DB2 z/OS Utilities Development
    IBM Germany

    Comment

    • eviewcs

      #3
      Re: Java UDT



      On Jan 30, 3:22 am, Knut Stolze <sto...@de.ibm. comwrote:
      eviewcs wrote:
      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 :

      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.SQLDat a;
      import java.sql.SQLExc eption;
      import java.sql.SQLInp ut;
      import java.sql.SQLOut put;
      >
      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(SQLInpu t 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(SQLOut put out)
      throws SQLException {
      out.writeString (strVal);
      out.writeInt(in tVal);
      out.writeString (String.valueOf (charVal));
      }
      >
      /**
      * test method in UDT
      * @return strVal + intVal + charVal
      */
      public String printAllAttr() {
      return strVal + "," + Integer.toStrin g(intVal) + "," +
      String.valueOf( charVal);
      }
      >
      /**
      * test method in UDT
      * @param newStr
      */
      public void changestring(St ring newStr) {
      strVal = newStr;
      }
      }
      >
      On the sql side :
      >
      CREATE TYPE EVIE.TEST_T1
      EXTERNAL NAME 'EVIE.TESTUDT:m yProject.TestUd t'
      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:m yProject.TestUd t';
      >
      I have compiled and archived myProject.TestU dt to a jar , and
      installed it using sqlj.install_ja r command namely TESTUDT.jar under
      user EVIE in my DB2.
      >
      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.
      >
      --
      Knut Stolze
      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?

      Comment

      • Knut Stolze

        #4
        Re: Java UDT

        eviewcs wrote:
        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 :

        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.SQLDat a;
        import java.sql.SQLExc eption;
        [...]
        }
        >
        >
        On the sql side :
        >
        CREATE TYPE EVIE.TEST_T1
        EXTERNAL NAME 'EVIE.TESTUDT:m yProject.TestUd t'
        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:m yProject.TestUd t';
        I have question on this statement of yours: DB2 does not support this syntax
        (see here:
        http://publib.boulder.ibm.com/infoce.../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:m yProject.TestUd t'
        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';


        --
        Knut Stolze
        DB2 z/OS Utilities Development
        IBM Germany

        Comment

        • eviewcs

          #5
          Re: Java UDT

          On Jan 31, 4:19 am, Knut Stolze <sto...@de.ibm. comwrote:
          eviewcs wrote:
          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 :

          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.SQLDat a;
          import java.sql.SQLExc eption;
          [...]
          }
          >
          On the sql side :
          >
          CREATE TYPE EVIE.TEST_T1
          EXTERNAL NAME 'EVIE.TESTUDT:m yProject.TestUd t'
          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:m yProject.TestUd t';
          >
          I have question on this statement of yours: DB2 does not support this syntax
          (see here:http://publib.boulder.ibm.com/infoce...m.ibm.db2....).
          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:m yProject.TestUd t'
          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';
          >
          --
          Knut Stolze
          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.

          Comment

          Working...