通过 JDBC API 获取 JDBC API 级别?

问题描述 投票:0回答:2

是否可以通过 JDBC API 获得 JDBC 级别的 API 支持?

3.0
3.1
4.0
4.1
4.2
等等...

https://en.wikipedia.org/wiki/Java_Database_Connectivity

jdbc
2个回答
0
投票

是的,您可以使用

这是在 Java 1.4 (JDBC 3) 中添加的;请注意,没有 JDBC 3.1。

那么

Connection connection = ....
DatabaseMetaData dbmd = connection.getMetaData();
System.out.printf("JDBC: %d.%d%n", dbmd.getJDBCMajorVersion(), dbmd.getJDBCMinorVersion());

0
投票

对于:

<dependency>
  <groupId>com.oracle.weblogic</groupId>
  <artifactId>ojdbc7</artifactId>
  <version>12.1.3-0-0</version>
</dependency>
<dependency>
  <groupId>org.apache.derby</groupId>
  <artifactId>derby</artifactId>
  <version>10.13.1.1</version>
</dependency>
<dependency>
  <groupId>com.h2database</groupId>
  <artifactId>h2</artifactId>
  <version>1.4.195</version>
</dependency>
<dependency>
  <groupId>hsqldb</groupId>
  <artifactId>hsqldb</artifactId>
  <version>1.8.0.10</version>
</dependency>

和:

    Class.forName(org.hsqldb.jdbcDriver.class.getCanonicalName());
    Connection conn = DriverManager.getConnection("jdbc:hsqldb:mem:mydb", "sa", "");
    System.out.println(String.format("HSQLDB: %s.%s", meta.getJDBCMajorVersion(), meta.getJDBCMinorVersion()));

    Class.forName(org.h2.Driver.class.getCanonicalName());
    conn = DriverManager.getConnection("jdbc:h2:mem:mydb", "sa", "");
    System.out.println(String.format("H2: %s.%s", meta.getJDBCMajorVersion(), meta.getJDBCMinorVersion()));

    Class.forName(org.apache.derby.jdbc.EmbeddedDriver.class.getCanonicalName());
    conn = DriverManager.getConnection("jdbc:derby:memory:mydb;create=true");
    System.out.println(String.format("Derby: %s.%s", meta.getJDBCMajorVersion(), meta.getJDBCMinorVersion()));

    Class.forName(oracle.jdbc.driver.OracleDriver.class.getCanonicalName());
    conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE", "sa", "");
    System.out.println(String.format("Oracle: %s.%s", meta.getJDBCMajorVersion(), meta.getJDBCMinorVersion()));

我有:

HSQLDB: 3.0
H2: 4.0
Derby: 4.2
Oracle: 4.1

com.oracle:ojdbc6:11.2.0.3
有趣的不一致:

Oracle: 1.12
© www.soinside.com 2019 - 2024. All rights reserved.