File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes JPQL String Function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "JPQL String Function" Watch "JPQL String Function" New topic
Author

JPQL String Function

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
I am unable to find the right usage for LOCATE string function.


i use like this-

-----------
select LOCATE(steering, horn, 1) from Car
--------------

here steering and horn are the column's for Car table.

if i modify the query like this and run in Apache Derby Client, it give's me error. I haven't yet tried thru EJB3 JPA.

---------------
select LOCATE(steering, hor, 1) from Car
------------------

error
-------------------
Error: Column 'HOR' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'HOR' is not a column in the target table.
SQLState: 42X04
ErrorCode: -1
-----------------------

i want to first run it cleanly here before i do run thru JPA.


SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

What is that column called "hor" in your SQL ? And also be careful, not all databases support the third argument for LOCATE.


[My Blog]
All roads lead to JavaRanch
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
hor is not a column. It is a searchable string.


LOCATE(searchString, stringToBeSearched), so why should i expect i'st and 2nd parameters as arguments.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Don't you have to put strings into quotations ? If you don't, the container will think it's an entity field.
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
Great!

it works like this (mine silling mistake)

select locate("steering", "hor", 1) from Car

there is no syntax specified under EJB 3 in Action for its usage.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPQL String Function