[MonetDB-users] JDBC: Problem with PreparedStatement parameter in Buffer
Hi all, I am trying to use PreparedStatement to get a buffer of a geometry invoking the commands bellow PreparedStatement st = con.prepareStatement("CREATE TABLE geom (g
geometry)"); st.execute(); st = con.prepareStatement("INSERT INTO geom VALUES(GeomFromText('POINT(1 1)', 2100))"); st.execute(); st = con.prepareStatement("SELECT Buffer(t.g, ?) AS buffer, t.g AS point FROM geom AS t"); // This line throws an SQLException st.setFloat(1, (float)1.0); ResultSet results = st.executeQuery();
However the fifth line throws an SQLException with this message:
types geometry(0,0) and double(53,0) are not equal
Replacing the question mark with a number (e.g. 1.0) the program executes properly. Why is this exception thrown? Is something wrong in my code? Thanks in advance, George Garbis
On 10-10-2011 12:04:16 +0300, George Garbis wrote:
st = con.prepareStatement("SELECT Buffer(t.g, ?) AS buffer, t.g AS point FROM geom AS t"); // This line throws an SQLException
All queries from your mail, and in particular this one is misuse of the prepared statement. The question mark is meant to be used on positions where it is clearly known what type is to be expected, e.g.: SELECT x, y FROM table WHERE id = ?;
st.setFloat(1, (float)1.0);
You better just do string manipulation here, and send that to the server.
According to function declaration the second argument is float
CREATE FUNCTION Buffer(a Geometry, distance FLOAT) RETURNS Geometry
external name geom."Buffer";
So, why it is not clear what type to be expected ?
Is there any way to use question marks as function arguments?
--
George Garbis
On Mon, Oct 10, 2011 at 12:11 PM, Fabian Groffen
On 10-10-2011 12:04:16 +0300, George Garbis wrote:
st = con.prepareStatement("SELECT Buffer(t.g, ?) AS buffer, t.g AS point FROM geom AS t"); // This line throws an SQLException
All queries from your mail, and in particular this one is misuse of the prepared statement. The question mark is meant to be used on positions where it is clearly known what type is to be expected, e.g.: SELECT x, y FROM table WHERE id = ?;
st.setFloat(1, (float)1.0);
You better just do string manipulation here, and send that to the server.
------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 _______________________________________________ MonetDB-users mailing list MonetDB-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-users
participants (2)
-
Fabian Groffen
-
George Garbis