This topic provides an example of using OceanBase Connector/J to connect to a database. Note
You must set the prefix of the connection string to jdbc:oceanbase. All other settings are the same as those in native MySQL.
String url = "jdbc:oceanbase://Connection string: 1521/SYS";
String username = "SYS";
String password = "***";
Connection conn = null;
try {
Class.forName("com.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();
rs.next();
System.out.println("sysdate is:" + rs.getString(1));
rs.close();
ps.close();
} catch (Throwable e) {
e.printStackTrace();
} finally {
if (null != conn) {
conn.close();
}
}