1. 添加 Maven 依赖
    1. <dependency>
    2. <groupId>com.alipay.oceanbase</groupId>
    3. <artifactId>oceanbase-client</artifactId>
    4. </dependency>

    说明

    如果需要下载 OceanBase JDBC 驱动,请点击:oceanbase-client

    1. 修改连接字符串

      连接串的前缀需要设置为 jdbc:oceanbase:oracle ,其他部分的使用方式与 JDBC 标准保持一致。

    1. String url = "jdbc:oceanbase:oracle://IP:端口/库名?连接参数";
    2. String username = "用户名";
    3. String password = "密码";
    4. Connection conn = null;
    5. try {
    6. Class.forName("com.alipay.oceanbase.Driver");
    7. conn = DriverManager.getConnection(url, username, password);
    8. PreparedStatement ps = conn.prepareStatement("select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') from dual;");
    9. ResultSet rs = ps.executeQuery();
    10. if (rs.next()) {
    11. System.out.println("sysdate is:" + rs.getString(1));
    12. }
    13. rs.close();
    14. ps.close();
    15. } catch (Exception e) {
    16. e.printStackTrace();
    17. } finally {
    18. if (null != conn) {
    19. conn.close();
    20. }
    21. }

    说明

    对于 Druid 框架,推荐使用 Druid 1.2.4 及以上版本:https://github.com/alibaba/druid/releases