Hi,
I tried to define a type "point3d" with some member functions, implemented in java, in my database. Therefor I implemented a class Point3dj.java as you can see it below and loaded it with "loadjava -user ... -resolve -verbose Point3dj.java" into the database.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
package spatial.objects;
import java.sql.*;
public class Point3dj implements java.sql.SQLData {
public double x;
public double y;
public double z;
public void readSQL(SQLInput in, String type)
throws SQLException {
x = in.readDouble();
y = in.readDouble();
z = in.readDouble();
}
public void writeSQL(SQLOutput out)
throws SQLException {
out.writeDouble(x);
out.writeDouble(y);
out.writeDouble(z);
}
public String getSQLTypeName() throws SQLException {
return "Point3dj";
}
public Point3dj(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
/*
public static Point3dj create(double x, double y, double z)
{
return new Point3dj(x,y,z);
}
*/
public double getNumber()
{
return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
}
public static double getStaticNumber(double px, double py, double pz)
{
return Math.sqrt(px*px+py*py+pz*pz);
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Additionally, I created the corresponding type in SQL by
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CREATE OR REPLACE TYPE point3dj AS OBJECT EXTERNAL NAME
'spatial.objects.Point3dj' LANGUAGE JAVA USING SQLDATA (
x FLOAT EXTERNAL NAME 'x',
y FLOAT EXTERNAL NAME 'y',
z FLOAT EXTERNAL NAME 'z',
MEMBER FUNCTION getNumber RETURN FLOAT
EXTERNAL NAME 'getNumber() return double',
STATIC FUNCTION getStaticNumber(xp FLOAT, yp FLOAT, zp FLOAT) RETURN FLOAT
EXTERNAL NAME 'getStaticNumber(double, double, double) return double')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
After that I tried some SQL commands:
create table pointsj of point3dj;
insert into pointsj values (point3dj(2,1,1));
SELECT x, a.getnumber() FROM pointsj a;
Now, the problem:
Everything works fine, if I delete the constructor
public Point3dj(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
in the java class, or if I replace it with a constructor that has no input arguments.
But with this few code lines in the java file, I get an error when executing the SQL command
SELECT x, a.getnumber() FROM pointsj a;
The Error is:
"ORA-00932: inconsistent data types: an IN argument at position 1 that is an instance of an Oracle type convertible to an instance of a user defined Java class expected, an Oracle type that could not be converted to a java class received"
I think, there are some problems with the input argument of the constructor, but why? I don't need the constructor in SQL, but it is used by a routine of another java class, so I can't just delete it.
Can anybody help me? I would be very glad about that since I already tried a lot and also search in forums and so on, but wasn't successful up to new.
Thanks!