ballerinax/java.jdbc Ballerina library
This package provides the functionality required to access and manipulate data stored in any type of relational database that is accessible via Java Database Connectivity (JDBC).
Prerequisite: Add the JDBC driver corresponding to the database you are trying to interact with
as a native library dependency in your Ballerina project. Then, once you build the project by executing the
command, you should be able to run the resultant by executing the
ballerina run command.
Change the path to the JDBC driver appropriately.
To access a database, you must first create a jdbc:Client object. The examples for creating a JDBC client can be found below.
Creating a client
This example shows the different ways of creating the
jdbc:Client. The client can be created by passing
the JDBC URL, which is a mandatory property and all other fields are optional.
dbClient1 receives only the database URL and the
dbClient2 receives the username and password in addition to the URL.
If the properties are passed in the same order as it is defined in the
jdbc:Client, you can pass it
without named params.
dbClient3 uses the named params to pass all the attributes and provides the
options property in the type of
and also uses the unshared connection pool in the type of
For more information about connection pooling, see SQL Package.
dbClient4 receives some custom properties within the
and those properties will be used by the defined
As per the provided example, the
org.h2.jdbcx.JdbcDataSource datasource will be configured with a
2000 milli seconds.
You can find more details about each property in the jdbc:Client constructor.
For more information on all the operations supported by the
jdbc:Client, which include the below, see the
- Connection Pooling
- Querying data
- Inserting data
- Updating data
- Deleting data
- Batch insert and update data
- Execute stored procedures
- Closing client
For examples on the usage of the connector, see the following.