Fix JDBC river

Merge latest from upstream.
Add sorting to SQL.