9

I am new to JPA, I used to used prepared statement in JDBC. Is there alternative to be used within JPA ? as there is a query which I call frequently

see this for info about prepared statment http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html

thanks in advance,,,

1
  • 1
    Suggest that you read up on JPA first and such a question would be answered in the most basic JPA tutorial ... Mar 15, 2010 at 15:12

3 Answers 3

9

The JPA way is EntityManager#createQuery() with named parameters in JPQL (examples in this chapter).

1
  • 2
    After 3 years, Thanks Balus
    – mebada
    Sep 2, 2013 at 7:47
3

The Java Persistence API provides a Query API to create dynamic queries and named queries. The Query method setParameter binds an argument to a parameter (both named queries and dynamic queries can use named parameters as well as positional parameters, you just can't mix both types of parameters).

Have a look at Creating Queries Using the Java Persistence Query Language in tha Java eE 6 tutorial for examples.

0
0

What are you trying to accomplish? =)

If you have a statement which you use rather often, wouldn't that be a good reason to put it in a method in a session bean/DAO?

1
  • JPA doesn't use statements though. It uses queries and named queries.
    – David Mann
    Feb 25, 2013 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.