Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. 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

Insert byte[] into BIT data type in MySQL using Java

First, you need to create a database and table as below to work with the following sample.


Sample:

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 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