Showing posts with label Ballerina. Show all posts
Showing posts with label Ballerina. Show all posts

Wednesday, May 29, 2019

Insert byte[] as a direct value to MySQL update operation in Ballerina

Ballerina version used: 0.992.0

Working with JDBC Client Call Procedures with BIT data type using Ballerina

This sample explains how to execute stored procedures using JDBC Client with BIT data type. Before running the sample, copy the MySQL JDBC driver to the BALLERINA_HOME/bre/lib folder.

Sample:
Ballerina version used: 0.992.0

How to run:

ballerina run callProcedureWithBitDataType.bal

Output:

Creating table and procedures:
Create bittypes table status: 0
Update bittypes table status: 1
Update bittypes table using sql:Parameter. status: 1
Update bittypes table by passing as direct parameter. status: 1
Stored procedure with IN and OUT param creation status: 0
Call operation with OUT params successful
=============bitVal1============= true
=============bitVal2============= 258
Drop stored procedure TestBitOutParam status: 0

Working with Postgresql database using Ballerina

  1. First, install Postgresql database.
  2. Download the postgresql driver jar and copy the Postgresql JDBC driver jar into $BALLERINA_HOME/bre/lib.
  3. Connect to your postgresql server and create a database:

Sample

This is the sample to create a table using the Ballerina jdbc client, then insert a BIT data type record to the table.

Ballerina version used: 0.992.0


Running the sample:

ballerina run workingWithBitDataPostgresql.bal

Output:

Create BitTypes table status: 0
Update BitTypes table status: 1

Working with an Oracle database using Ballerina

Ballerina version used: 0.992.0
Oracle database version used: Oracle-xe-11g (Follow these instructions explained here to install Oracle-xe-11g with Docker).


This Sample is written using ballerinax/jdbc module. Before running this sample you need to copy the Oracle JDBC driver jar into $BALLERINA_HOME/bre/lib.

First, create the table using the following command:

This is a sample to insert byte array into oracle database:

Running the sample:

ballerina run insertByteArray.bal

Output:

Update oracledb table status: 1

Working with mysql BIT data type using Ballerina

This example is written using Ballerina MYSQL Client which is used to access and manipulate data in MYSQL databases.
  1. First, you need to install MySQL. 
  2. Download and install Ballerina 0.992.0.
  3. Copy the MySQL JDBC driver(mysql-connector-java-5.1.39.jar) to the BALLERINA_HOME/bre/lib folder and change the DB connection properties as required.
Sample


How to run:

ballerina run workingWithBitData.bal

Output:
Create database testdb status: 1
Create bittypes table status: 0
Update bittypes table status: 1
Update bittypes table status: 1
===================================
1
true
[0, 0, 0, 0, 0, 0, 0, 14]
2
true
[0, 0, 0, 0, 0, 1, 2, 3]
===================================
Drop Database testdb status: 1