Skip to main content

@java.sql.Query and parameter marker

2 replies [Last post]
Joined: 2005-07-12


In the java.sql.Query 's API we can read :
Parameter markers are defined as a string value enclosed by braces '{}'.
The parameter marker's string value must directly map to a parameter name of the method that was decorated by the Query annotation.

But actually the name of the parameter is not checked. Each parameter markers is replaced by the parameter of the method in apparition order.
So the following method will not work (login and password parameter are not in the correct order) :

@Query("select * from table where password = {password} and login = {login}")
public DataSet login(String login, String password);

If I'm not mistaken, it's not possible to get the name of the parameters of a method with the reflect API.
Therefore, either it will be a new functionality implemented in a future version of mustang, either it's necessary to modify the documentation...

I'm sorry for my poor english (it's not my language).

Thank you to answer me

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-13

The latest versionfs of the specfication ahve changed the semantics for the use of parameter markers for the reasons that you state below.

Joined: 2004-10-07

I have found this bugs :

that give no news but getParameterAnnotations()
is not very usefull if you can't retreive parameter names
so it could be a nice addition.

The problem is that method parameter name are kept at
runtime only as a debug information (in the same places
that all local variables), so these informations
could not be present.

So if you want correctly implements getParameterNames(),
you have to change the cirtual macine specification
to add a new attribute that contains parameter names.

Rémi Forax