Search code examples
jdbcpeppython-db-api

Database API specification for Java


Is there a Database API specification for Java that is similar to what exists for Python (PEP249).

I'd like to make an application that can be used to connect to databases, universally, without worrying about the database engine type.


Solution

  • Yes, such an API exists and - AFAIK - it predates Python efforts at standardization. This specification and its API is called JDBC or Java DataBase Connectivity. The current version is JDBC 4.2 (with JDBC 4.3 currently in the pipeline), also identified as JSR 221: JDBCTM 4.0 API Specification maintenance release 2.

    You can find the specification document at https://jcp.org/en/jsr/detail?id=221

    The interfaces of the API are included in main Java API. See the packages java.sql and javax.sql.

    See the Java Tutorial Trail: JDBC(TM) Database Access for an introduction.

    A JDBC specification is tied to a Java version, so:

    • Java 9: JDBC 4.3
    • Java 8: JDBC 4.2
    • Java 7: JDBC 4.1
    • Java 6: JDBC 4.0
    • ... earlier versions are not that interesting anymore

    JDBC versions are generally additive, so features in earlier versions are carried over into newer version, and - bar some early mistakes - are usually not deprecated. Sometimes minor clarifications or semantic changes can be made in newer versions of the specification.

    Be aware that features in newer JDBC versions are (usually) only accessible if the driver actually implements that JDBC version.

    Disclosure: I am a member of the JDBC Expert Group