File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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

How to pass request parameters to Query

Kir Swa

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.


Bill Gorder

Joined: Mar 07, 2010
Posts: 1646

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

Joined: May 03, 2012
Posts: 9
Thanks Bill, Its working now.
Consider Paul's rocket mass heater.
subject: How to pass request parameters to Query
Similar Threads
HQL query with OneToMany
Basic Hibernate many-to-many mapping / query not right
fetching records by using hql and criteria is taking more time
Deleting Record in a Web Application.
[Hibernate] Join without FK Relationship using Criteria