You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by RB...@intersoft.de on 2003/08/20 09:20:38 UTC

How to create a LIKE Statement???

Hi,
I´m trying to make a 

SELECT * FROM Table WHERE Field LIKE 'XY%'

I thought a 

Criteria theCriteria = new Criteria();
theCriteria.addLike("myAttributeName", anAttributeValue);
// where the Attribute Type is BigDecimal


should do the Job.


But I´m getting a ClassCastException (I think because of the String-Cast 
at the "addLike(...)" method of Criteria.

But even a:
theCriteria.addLike("myAttributeName", anAttributeValue+"*");

leads to a ClassCastException because of the DatabaseType BigDeciamal or 
NUMERIC.

Any help would be appreciated!
 

Greetings,
Mit freundlichen Grüßen,

Ralf Baron-Riege


___________________________________
intersoft AG, Hamburg
E-Mail: RBaron-Riege@intersoft.de
http://www.intersoft.de
Fon +49 40 80 81 08 - 224
Fax +49 40 80 81 08 - 141

Re: How to create a LIKE Statement???

Posted by LAURENT Stephane <bi...@sportmalin.com>.
Hi,
I'm not sure you can have a "like" clause on numeric field in sql queries or
you are using database specific function.
When your (database) field is numeric, the generated query don't have quotes
(like myField=3) so in your case, you try to generate a clause like this :
myField=3% ...
if you can do SELECT * FROM Table WHERE Field LIKE 'XY%' on your
SQLWorksheet, with Field numeric, I thing your database have an automatic
conversion function like this : SELECT * FROM Table WHERE toString(Field)
LIKE 'XY%'
Purapse your database field is varchar and OJB map it to BigInt (can do it
?) ?
So try this : theCriteria.addLike("myAttributeName",
anAttributeValue.toString());
Not sur of the result, but can work ...
else, you can directly add your SQL clause but you have to know the database
name ... so no database model abstaction

PS : Why don't create criteria with function on attribute like this :

theCriteria.addLike("myAttributeName", anAttributeValue,
"myDatabaseFunction");
theCriteria.equalTo("myAttributeName", anAttributeValue,
"myDatabaseFunction");
...
where myAttributeName is mapped to Field in Table
generating query like this :
SELECT * FROM Table WHERE myDatabaseFunction(Field) LIKE 'XY%'
SELECT * FROM Table WHERE myDatabaseFunction(Field)='XY'

or
theCriteria.equalTo("myAttributeName", anAttributeValue,
"myDatabaseFunction", myDatabaseFunctionParameters );
where myDatabaseFunctionParameters could be an array of object (numeric or
string to add quotes or not)
SELECT * FROM Table WHERE myDatabaseFunction(Field,a,'b')='XY'

Could be a solution to open OJB to database specific function and "inSQL"
stored procedure call, no ?


----- Original Message ----- 
From: <RB...@intersoft.de>
To: <oj...@db.apache.org>
Sent: Wednesday, August 20, 2003 9:20 AM
Subject: How to create a LIKE Statement???


Hi,
I´m trying to make a

SELECT * FROM Table WHERE Field LIKE 'XY%'

I thought a

Criteria theCriteria = new Criteria();
theCriteria.addLike("myAttributeName", anAttributeValue);
// where the Attribute Type is BigDecimal


should do the Job.


But I´m getting a ClassCastException (I think because of the String-Cast
at the "addLike(...)" method of Criteria.

But even a:
theCriteria.addLike("myAttributeName", anAttributeValue+"*");

leads to a ClassCastException because of the DatabaseType BigDeciamal or
NUMERIC.

Any help would be appreciated!


Greetings,
Mit freundlichen Grüßen,

Ralf Baron-Riege


___________________________________
intersoft AG, Hamburg
E-Mail: RBaron-Riege@intersoft.de
http://www.intersoft.de
Fon +49 40 80 81 08 - 224
Fax +49 40 80 81 08 - 141


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: How to create a LIKE Statement???

Posted by Alexander Prozor <ap...@isd.dp.ua>.
It works well with non number fields.
I think that you have to look at generated SQL and trying to build right 
criteria.
(you can see all generated SQL queries by setting 
driver="com.p6spy.engine.spy.P6SpyDriver" in datavase_repository.xml file)
sorry, if it will not help you, but I've never used like criteria with 
NUMBER fields.

>Hi,
>I´m trying to make a 
>
>SELECT * FROM Table WHERE Field LIKE 'XY%'
>
>I thought a 
>
>Criteria theCriteria = new Criteria();
>theCriteria.addLike("myAttributeName", anAttributeValue);
>// where the Attribute Type is BigDecimal
>
>
>should do the Job.
>
>
>But I´m getting a ClassCastException (I think because of the String-Cast 
>at the "addLike(...)" method of Criteria.
>
>But even a:
>theCriteria.addLike("myAttributeName", anAttributeValue+"*");
>
>leads to a ClassCastException because of the DatabaseType BigDeciamal or 
>NUMERIC.
>
>Any help would be appreciated!
> 
>
>Greetings,
>Mit freundlichen Grüßen,
>
>Ralf Baron-Riege
>



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org