File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes How to pass request parameters to Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to pass request parameters to Query" Watch "How to pass request parameters to Query" New topic
Author

How to pass request parameters to Query

Kir Swa
Greenhorn

Joined: May 03, 2012
Posts: 9
Iam trying get records from DB based on request parameter. Here is my code

at line 1 iam getting exception:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'O0001' in 'where clause'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)...........

I executed same Query in MySQL, there it is working, and the Query is SELECT * FROM tablename WHERE id='O0001'; How will i write same Query(passing request parameter instead of entering manually) in createQuery()

Iam new to Hibernate. Can someone help me in finding the solution.

Thanks



Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1676
    
    7

Please UseCodeTags when posting code or configuration. I have added them for you this time so you can see the difference in readability.

Try using named parameters.


This assumes that your OrderBean object has a property named 'id' also if this is the case are you really expecting a list here or a single result. If the latter have a look at doing something like this instead.


.


[How To Ask Questions][Read before you PM me]
Kir Swa
Greenhorn

Joined: May 03, 2012
Posts: 9
Thanks Bill, Its working now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to pass request parameters to Query