- Add a Maven dependency
<dependency>
<groupId>com.alipay.oceanbase</groupId>
<artifactId>oceanbase-client</artifactId>
</dependency>
Note
To download the OceanBase JDBC driver, click oceanbase-client.
Modify the connection string
The prefix of the connection string must be
jdbc:oceanbase:oracle. The settings of other parameters of the string are the same as those of native MySQL connection strings.
String url = "jdbc:oceanbase:oracle://IP: port/database name?Connection parameters";
String username = "Username";
String password = "Password";
Connection conn = null;
try {
Class.forName("com.alipay.oceanbase.jdbc.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();
}
}
Note
As for the Druid framework, we recommend that you use Druid 1.2.4 or later. For more information, seehttps://github.com/alibaba/druid/releases.