This topic describes common Java APIs and provides examples.
Overview of common Java APIs
The following table lists common Java APIs.
For more information about the APIs, see OceanBase Connector/J.
| API | Description |
|---|---|
| java.sql.Connection | A database connection interface. |
| java.sql.CallableStatement | An interface for executing stored procedures. |
| java.sql.DatabaseMetaData | An interface for defining database objects. |
| java.sql.Driver | A database driver interface. |
| java.sql.PreparedStatement | A prepared statement interface. |
| java.sql.ParameterMetaData | An interface for obtaining parameter information. |
| java.sql.ResultSet | An interface for executing result sets. |
| java.sql.ResultSetMetaData | An interface for describing ResultSet objects. |
| java.sql.Statement | An SQL statement interface. |
| javax.sql.ConnectionPoolDataSource | A data source connection pool interface. |
| javax.naming.Context | A context interface for connection configuration. |
| javax.sql.PooledConnection | A connection interface created by a connection pool. |
Examples
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();
}
}