Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDBC PreparedStatement won't work with parameter as last element #45

Closed
julianhowarth opened this issue Jul 13, 2017 · 4 comments
Closed

Comments

@julianhowarth
Copy link

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.

@dwayneberry
Copy link
Contributor

@julianhowarth Thanks for that.

Are you thinking you might prepare PR to fix this?

@julianhowarth
Copy link
Author

I can do - do you have a set of contributor guidelines/requirements?

@dwayneberry
Copy link
Contributor

@julianhowarth

Great, thanks

Yes please see https://github.com/mapd/mapd-core#contributing

@Smyatkin-Maxim
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants