- 添加 Maven 依赖
<dependency>
<groupId>com.alipay.oceanbase</groupId>
<artifactId>oceanbase-client</artifactId>
</dependency>
说明
如果需要下载 OceanBase JDBC 驱动,请点击:oceanbase-client
修改连接字符串
连接串的前缀需要设置为
jdbc:oceanbase:oracle
,其他部分的使用方式与 JDBC 标准保持一致。
String url = "jdbc:oceanbase:oracle://IP:端口/库名?连接参数";
String username = "用户名";
String password = "密码";
Connection conn = null;
try {
Class.forName("com.alipay.oceanbase.Driver");
conn = DriverManager.getConnection(url, username, password);
PreparedStatement ps = conn.prepareStatement("select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') from dual;");
ResultSet rs = ps.executeQuery();
if (rs.next()) {
System.out.println("sysdate is:" + rs.getString(1));
}
rs.close();
ps.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != conn) {
conn.close();
}
}
说明
对于 Druid 框架,推荐使用 Druid 1.2.4 及以上版本:https://github.com/alibaba/druid/releases。