Andrey Belykh
Andrey Belykh

Reputation: 2654

How to determine if the JDBC driver supports PreparedStatement?

Is there a way to programmatically detect if the particular JDBC driver supports PreparedStatement without calling executeQuery() and catching "not implemented" exception?

Upvotes: 0

Views: 139

Answers (1)

Mark Rotteveel
Mark Rotteveel

Reputation: 109240

Any compliant JDBC driver must implement prepared statement. If you have a driver that doesn't support prepared statements, it is formally not a JDBC driver (even if it implements (part of) the JDBC API).

As the JDBC specification requires support of prepared statements, there is nothing in the API to check if they are supported. Contact the vendor/author of this driver and tell them that prepared statements are not optional. This unfortunately means that you can't discover it until you execute.

Also, I would be rather surprised if any driver not supporting prepared statements would allow preparing statements but only fail at execute time. This would - to me - suggest that prepared statements are supported (otherwise why not just fail when Connection.prepareStatement is called), but that whatever you are doing is not supported (like calling executeQuery(String) instead of executeQuery()).

Upvotes: 2

Related Questions