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 NamedParameterJdbcTemplate and Function Call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "NamedParameterJdbcTemplate and Function Call" Watch "NamedParameterJdbcTemplate and Function Call" New topic

NamedParameterJdbcTemplate and Function Call

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Hey guys,

I am facing a little problem, which I think is owing to the underlying prepared statement of the jdbc template.

here is what i want to do.

The tricky part is the location, which is a longitude latitude pair which must be interpreted as a postgis geometry.

what the underlying implementation of params.addValue("location", bookingCreditTour.getLocation()) does is the following:

So the addValue method turns the LocationDV into a String ST_MakePoint(longitude, latitude).

Of course, the ST_MakePoint is a postgis function that needs to be evaluated on the db-server, and i think this is where the problem lies, as this does not go together with prepared statements (or at least i don't know how to).

I could turn the sql query into

but I would really like to encapsulate this away (especially as longitude and latitude tend to get mixed up).

In essence, the question is if there is a way to include this ST_MakePoint function call into the prepared statement.

Thanks for your help

JDBCSupport - An easy to use, light-weight JDBC framework -
I agree. Here's the link:
subject: NamedParameterJdbcTemplate and Function Call
It's not a secret anymore!