Module
java.jdbc
Module java.jdbc
ballerinax/java.jdbc
0.6.0-alpha9.1
Clients
java.jdbc: Client
Represents a JDBC client.
Constructor
Initialize JDBC client.
init (string url, string? user, string? password, Options? options, ConnectionPool? connectionPool)
- url string - The JDBC URL of the database
- user string? () - If the database is secured, the username of the database
- password string? () - The password of provided username of the database
- options Options? () - The Database specific JDBC client properties
- connectionPool ConnectionPool? () - The
sql:ConnectionPool
object to be used within the jdbc client. If there is no connectionPool is provided, the global connection pool will be used and it will be shared by other clients which has same properties.
query
Isolated FunctionRemote Function
function query(string|ParameterizedQuery sqlQuery, typedesc<record {}>? rowType) returns stream<record {}, Error>
Queries the database with the query provided by the user, and returns the result as stream.
Parameters
- sqlQuery string|ParameterizedQuery - The query which needs to be executed as
string
orParameterizedQuery
when the SQL query has params to be passed in
- rowType typedesc<record {}>? (default ()) - The
typedesc
of the record that should be returned as a result. If this is not provided the default column names of the query result set be used for the record attributes.
execute
Isolated FunctionRemote Function
function execute(string|ParameterizedQuery sqlQuery) returns ExecutionResult|Error
Executes the DDL or DML sql queries provided by the user, and returns summary of the execution.
Parameters
- sqlQuery string|ParameterizedQuery - The DDL or DML query such as INSERT, DELETE, UPDATE, etc as
string
orParameterizedQuery
when the query has params to be passed in
Return Type
- ExecutionResult|Error - Summary of the sql update query as
ExecutionResult
or returnsError
if any error occurred when executing the query
batchExecute
Isolated FunctionRemote Function
function batchExecute(ParameterizedQuery[] sqlQueries) returns ExecutionResult[]|Error
Executes a batch of parameterized DDL or DML sql query provided by the user, and returns the summary of the execution.
Parameters
- sqlQueries ParameterizedQuery[] - The DDL or DML query such as INSERT, DELETE, UPDATE, etc as
ParameterizedQuery
with an array of values passed in
Return Type
- ExecutionResult[]|Error - Summary of the executed SQL queries as
ExecutionResult[]
which includes details such asaffectedRowCount
andlastInsertId
. If one of the commands in the batch fails, this function will returnBatchExecuteError
, however the JDBC driver may or may not continue to process the remaining commands in the batch after a failure. The summary of the executed queries in case of error can be accessed as(<sql:BatchExecuteError> result).detail()?.executionResults
.
call
Isolated FunctionRemote Function
function call(string|ParameterizedCallQuery sqlQuery, typedesc<record {}>[] rowTypes) returns ProcedureCallResult|Error
Executes a SQL stored procedure and returns the result as stream and execution summary.
Parameters
- sqlQuery string|ParameterizedCallQuery - The query to execute the SQL stored procedure
- rowTypes typedesc<record {}>[] (default []) - The array of
typedesc
of the records that should be returned as a result. If this is not provided the default column names of the query result set be used for the record attributes.
Return Type
- ProcedureCallResult|Error - Summary of the execution is returned in
ProcedureCallResult
orsql:Error
close
Isolated Function
function close() returns Error?
Close the JDBC client.
Return Type
- Error? - Possible error during closing the client
Records
java.jdbc: Options
Closed record
Provides a set of configuration related to database.
Fields
- datasourceName string?(default ()) - The driver class name to be used to get the connection
- properties map<anydata>?(default ()) - the properties of the database which should be applied when getting the connection