By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,610 Members | 2,310 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,610 IT Pros & Developers. It's quick & easy.

Java UDT

P: n/a
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/developerwork...y/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?

Jan 29 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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 :
http://www-128.ibm.com/developerwork...y/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?
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
Jan 29 '07 #2

P: n/a


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 :
http://www-128.ibm.com/developerwork...y/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?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?

Jan 30 '07 #3

P: n/a
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 :
http://www-128.ibm.com/developerwork...y/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;
[...]
}
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 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: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';
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Jan 30 '07 #4

P: n/a
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 :
http://www-128.ibm.com/developerwork...y/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;
[...]
}
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 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: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';

--
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.

Jan 31 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.