Sqlite long parameter linked as a string with java 7 and not with java 6

I have a code that worked like a charm for many years. It broke with a recent java update on my Mac.

  • when using java 6 (1.6.0_65-b14-462-11M4609), it works as expected
  • when using java 7 (1.7.0_60-b19), it does not work.

Here's the test code:

PreparedStatement p = mConnection.prepareStatement("SELECT rowid, * FROM cases_customers WHERE case_id = ?");
p.setLong(1, 2);
ResultSet r = p.executeQuery();
System.out.println("One result? " + r.next());

p = mConnection.prepareStatement("SELECT rowid, * FROM cases_customers WHERE case_id = ? + '0'");
p.setLong(1, 2);
r = p.executeQuery();
System.out.println("At least one result? " + r.next());

Conclusion:

At least one result? false
At least one result? true

The second query forces the data to bind as a number due to the addition. Thus, even if the data is bound for so long in the code, it is somehow translated as a string later.

I have not changed my SQLite JDBC driver (which is xerial 3.7.2).

Java Web Start, / jar "" make GNU, javac . jar/app , true/true.

: Build configuration: default with option to start on UI thread on Mac

DB.java( sqlite-jdbc-3.7.2), DB#sqlbind:

else if (v instanceof Long) {
    return bind_long(stmt, pos, ((Long) v).longValue());
}
  • java 6, DB NativeDB.java native bind_long.
  • java 7, DB NestedDB.java :

.

@Override
synchronized int bind_long(long stmt, int pos, long v) throws SQLException {
    return bind_text(stmt, pos, Long.toString(v)); // TODO
}

long String.

+4
1

, . .

SQLite JDBC-, java 6 java- java 7. , java- long String s. JDBC , java 6, 7.

.

+3

Source: https://habr.com/ru/post/1547136/


All Articles