How to UPDATE or DELETE Derby Table fields of Java Objects with custom data type

Viewed 83

I have a Derby database with table for Java Objects. I have even created a custom data type of the class objects belong to.

The name of the custom data type is MYCURRENCY.

Now, while I can Insert data into table, am getting error during UPDATE & DELETE with Where clause.

Error - java.sql.SQLSyntaxErrorException: Comparisons between '"APP"."MYCURRENCY"' and '"APP"."MYCURRENCY"' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1')

My query for Updating :

query = "UPDATE CURRENCYTABLE SET currency = ? WHERE CAST(currency as MyCurrency) = ?";
                    pstmt = con.prepareStatement(query);
                    pstmt.setObject(1, newCurr);
                    pstmt.setObject(2, oldCurr);

For Deleting:

query = "DELETE FROM CURRENCYTABLE WHERE CAST(currency as MYCURRENCY) = ?";
                    pstmt = con.prepareStatement(query);
                    pstmt.setObject(1, curr);

The class from which objects are created has overriden equalsto & compareTo methods.

Please help in understanding how to compare Java objects in database without Hibernate (its a Swing Project)

0 Answers
Related