JDBC PreparedStatement won't work with parameter as last element
Using release 3.1.1 and the associated jdbc driver lib.
CREATE TABLE t (x INT NOT NULL);
In Java code, assuming properly set up connection:
PreparedStatement ps = conn.prepareStatement("SELECT x FROM t WHERE x = ?");
ps.setInt(1, 1)
fails with:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at com.mapd.jdbc.MapDPreparedStatement.setInt(MapDPreparedStatement.java:175)
This is due to the MapDPreparedStatement at https://github.com/mapd/mapd-core/blob/master/java/mapdjdbc/src/main/java/com/mapd/jdbc/MapDPreparedStatement.java#L84 initially splitting the SQL String using .split. The javadoc for that method states:
Trailing empty strings are therefore not included in the resulting array.
Therefore the subsequent line of code calculates the number of expected parameters as zero.
A simple workaround is to include an additional space at the end of the statement i.e. "SELECT x FROM t WHERE x = ? " but that shouldn't really be necessary.
@julianhowarth Thanks for that.
Are you thinking you might prepare PR to fix this?
I can do - do you have a set of contributor guidelines/requirements?
@julianhowarth
Great, thanks
Yes please see https://github.com/mapd/mapd-core#contributing
What's the current status on this one? I see it has been three months since last update, may I take it after I'm done with #29? This one looks quite easy.