Search code examples
javajdbcamazon-athenajdbipresto

Using JDBI with a JDBC driver that does not support prepared statements


I'm trying to use the latest 2.x version of JDBI on top of the Presto/AWS Athena jdbc driver which does not support prepared statements.

It seems like there should be a configuration option or such that would allow you to turn off the use of prepared statements, especially if you just pass in SQL with no parameters to bind. However, the StatementBuilder interface requires a PreparedStatement return value from the create method.

Has anyone run into this or have some advice about how to use JDBI in this case? I'm using it across the rest of my project for several other databases so would prefer to keep it for consistency.


Solution

  • If you must use JDBI with a JDBC driver that doesn't support PreparedStatement, you have two choices:

    1. JDBI is open-source. Modify the source to fit your need. If you do it in a generally useful way, you might want to post the updates back, so others can benefit it, i.e. become a contributor.

    2. Fake it. Create a JDBC wrapper around the JDBC connection from Presto/AWS Athena, that returns a fake PreparedStatement, supporting only parameter-less SQL statements, i.e. throws UnsupportedOperationException if any of the setXxx methods are called. You then give the wrapped connection to JDBI.