This topic describes general Java APIs and provides an example.
Overview
The following table lists the general Java APIs.
For more information about the APIs, see General APIs in User Guide of OceanBase Connector/J.
| Operation | Description |
|---|---|
| java.sql.Connection | Connects to a specified database. |
| java.sql.CallableStatement | Executes stored procedures. |
| java.sql.DatabaseMetaData | Defines database objects. |
| java.sql.Driver | Runs a database driver to connect to a database. |
| java.sql.PreparedStatement | Compiles and converts SQL statements. |
| java.sql.ParameterMetaData | Queries parameter metadata. |
| java.sql.ResultSet | Generates execution result sets. |
| java.sql.ResultSetMetaData | Describes ResultSet objects. |
| java.sql.Statement | Executes SQL statements. |
| javax.sql.ConnectionPoolDataSource | Creates a physical database connection that can be used as a pooled connection. |
| javax.naming.Context | Connects configured context. |
| javax.sql.PooledConnection | Provides connections for the connection pool manager. |
Example
Query the current system time of OceanBase Database.
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();
}
}