rxjava2-jdbc
rxjava2-jdbc copied to clipboard
Same NamedParameters used multiple times
MySQL
String query = "SELECT * FROM table
WHERE ST_CONTAINS(GEOMFROMTEXT('POLYGON((:neLon :neLat, :neLon :swLat, :swLon :swLat, :swLon :neLat,:neLon :neLat))'), point)"
return database
.select(query)
.parameter("swLon", swLon)
.parameter("swLat", swLat)
.parameter("neLon", neLon)
.parameter("neLat", neLat)
.get(new Mapper())
This won't work but when I hardcode the lat's and lng's it works fine. Are we not allowed to use named parameters in multiple places and assign value only once?
Thank you very much for all your help!
Kind Regards, Vini
Repeated use of named parameters is allowed. The problem you have is no parameter substitution will occur in the middle of a quoted string. You would have to do something like this:
`POLYGON((`||:neLon||` `||:neLat||',' ...
@davidmoten Does it actually work? I have two parameters and each of them is used twice in the query. But still I got the following exception:
java.lang.IllegalArgumentException: number of values should be a multiple of number of parameters in sql