tags:

views:

401

answers:

4

Dear all,

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,,,

A: 

As opposed to using PreparedStatements you could look at EJB3 and Hibernate.

Marcus
That's not what the question is about.
Pascal Thivent
+2  A: 

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

BalusC
Or even a named query.
ewernli
A: 

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?

mikek
+1  A: 

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.

Pascal Thivent