OceanBase Connector/J can process PL stored procedures and anonymous blocks, and supports the PL block syntax and JDBC escape syntax.
The following PL calls can be used together with OceanBase Connector/J:
// The JDBC escape syntax.
CallableStatement ecs1 = conn.prepareCall
( "{call proc (?,?)}" ) ; // The stored procedure.
CallableStatement ecs2 = conn.prepareCall
( "{? = call func (?,?)}" ) ; // The stored function.
// The PL block syntax.
CallableStatement ecs3 = conn.prepareCall
( "begin proc (?,?); end;" ) ; // The stored procedure.
CallableStatement ecs4 = conn.prepareCall
( "begin ? := func(?,?); end;" ) ; // The stored function.
Function calls in OceanBase Connector/J:
OceanBaseDataSource obds = new OceanBaseDataSource();
obds.setURL("jdbc:oceanbase:oracle://Connection string:1521/username");
obds.setUser("Adam");
obds.setPassword("P@ssw0rd");
Connection conn = obds.getConnection();
CallableStatement cs = conn.prepareCall ("begin ? := f(?); end;");
cs.registerOutParameter(1,Types.CHAR);
cs.setString(3, "aaa");
cs.executeUpdate();
String result = cs.getString(1);
Example: Call a PL function to retrieve a character sequence and add a suffix to it.
CREATE OR REPLACE FUNCTION f (v CHAR)
RETURN CHAR AS
BEGIN
RETURN v || 'suffix';
END;