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? <string?> ()
  • If the database is secured, the username of the database

  • password string? <string?> ()
  • The password of provided username of the database

  • options Options? <ballerina/java.jdbc:0.5.0:Options?> ()
  • The Database specific JDBC client properties

  • connectionPool ConnectionPool? <ballerina/sql:0.5.0: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.

Remote Methods

query

Queries the database with the query provided by the user, and returns the result as stream.

execute

Executes the DDL or DML sql queries provided by the user, and returns summary of the execution.

batchExecute

Executes a batch of parameterized DDL or DML sql query provided by the user, and returns the summary of the execution.

call

Executes a SQL stored procedure and returns the result as stream and execution summary.

Methods

Close the JDBC client.

query

(string | ParameterizedQuery sqlQuery, typedesc? rowType)

returns stream<record {| anydata...; |} ,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 or ParameterizedQuery when the SQL query has params to be passed in

  • rowType typedesc? (default <typedesc<record {| anydata...; |}>?> ())
  • 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.

  • Return Type

    (stream<record {| anydata...; |} ,Error>)
  • Stream of records in the type of rowType

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 or ParameterizedQuery when the query has params to be passed in

  • Return Type

    (ExecutionResult | Error)
  • Summary of the sql update query as ExecutionResult or returns Error if any error occurred when executing the query

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 as affectedRowCount and lastInsertId. If one of the commands in the batch fails, this function will return BatchExecuteError, 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

(string | ParameterizedCallQuery sqlQuery, typedesc[] rowTypes)

returns ProcedureCallResult | Error

Executes a SQL stored procedure and returns the result as stream and execution summary.

Parameters

  • rowTypes typedesc[] (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.

close

()

returns Error?

Close the JDBC client.

  • Return Type

    (Error?)
  • Possible error during closing the client