Ballerina version used: 0.992.0
Wednesday, May 29, 2019
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:
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
Sample:
Ballerina version used: 0.992.0
How to run:
Output:
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
- First, install Postgresql database.
- Download the postgresql driver jar and copy the Postgresql JDBC driver jar into $BALLERINA_HOME/bre/lib.
- Connect to your postgresql server and create a database:
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:
Output:
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.
Output:
- First, you need to install MySQL.
- Download and install Ballerina 0.992.0.
- 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
Install SQL*Plus on Ubuntu 16.04
- First, you need to download Instant Client Downloads.
- Install alien software.
- Navigate to the folder where the downloaded rpm files are located and execute the following commands:
- Type following command to install libaio.so
- Create an Oracle configuration file:
- Put the following line in the created file:
- Update the configuration by running the following command:
- Try to connect using the following command:
sudo apt-get install alien
sudo alien -i oracle-instantclient*-basic*.rpm sudo alien -i oracle-instantclient*-sqlplus*.rpm sudo alien -i oracle-instantclient*-devel*.rpm
sudo apt-get install libaio1
sudo nano /etc/ld.so.conf.d/oracle.conf
/usr/lib/oracle/<your oracle version>/client64/lib/
sudo ldconfig
sqlplus system/oracle@localhost:49161/xe
Installing Oracle XE 11g on Ubuntu
Installing Oracle XE with Docker
Docker is an application container for Linux. It is based on LXC and gives you the ability to package complete application including their dependencies to a self-containing file called an image. These images can be exchanged and run on every Linux machine where Docker is installed. It is the easiest way to install Oracle XE. Docker images are also shared around the community on https://index.docker.io.
- First, you need to install Docker on Ubuntu. Follow the instructions given in this doc.
- Pull the image to your machine using the following command :
- Run the image using the following command :
- Connect to the database with the following setting:
- You can connect to the database using SQL*Plus
docker pull arahman/docker-oracle-xe-11g
docker run -d -p 49160:22 -p 49161:1521 -p 49162:8080 arahman/docker-oracle-xe-11g /sbin/my_init
hostname: localhost
port: 49161
sid: xe
username: system
password: oracle
Friday, April 19, 2019
Tracking Form Submissions
This is to send an event to Google Analytics when the contact form is submitted, with the following data:
- Event category: Form Submission
- Event action: Form Submitted
- Event label: Form ID: [Form ID]
When there are multiple forms on the website
and if you want to distinguish between forms, the event label will be replaced with the ID of the form is submitted.
Enable the required variables
Go to the Variables screen and enable the built-in variables called Form Element and Form ID by ticking the checkbox. At least one form variable must be enabled to ensure GTM records form submissions.
Create a trigger
Go to the Triggers screen and create a new trigger called Form Submission, trigger type as Form Submission.
Then you can choose if you want the trigger to fire on all form submissions or specific forms. If you want to fire on specific forms, click on SOme Forms radio button checked, then save the trigger. In the appeared text boxes you can specify conditions.
Create a tag
Create a Universal Analytics tag to fire the event to Google Analytics.
Go to the tags screen and create a tag called GA Form Submission Tag.
Choose the Universal Analytics tag type.
Enter your Google Analytics property ID.
Select Event from the Track Type dropdown menu.
Enter your event category, action and label values as appropriate (remember to use the Form ID variable in the event label).
Finally, attach the created Form Submission trigger to the tag.
Saturday, December 1, 2018
Tracking Outgoing Link Clicks
This is to record events in Google Analytics whenever someone clicks an outbound link on our website.
- Event Category: Outside Interactions
- Event Action: Outbound Link Clicked
- Event Label: [Click URL]
Google Tag Manager can detect DOM events triggered by the browser such as clicks on
elements and form submissions. This is known as Auto-Event tracking,
because we are listening for default events and not having to write any
additional code on the website.
To accomplish our goal, we can listen for all clicks on <a> elements, where the HREF attribute does not contain our domain name.
To accomplish our goal, we can listen for all clicks on <a> elements, where the HREF attribute does not contain our domain name.
Enable the Click URL variable
In order to determine if a link is an internal or outbound one, we need to know the value of the HREF attribute. GTM can automatically record this and set it in a variable.
Go to the Variables screen and then click the Configure button.
Check the Click URL checkbox and then close the popup window. After that, you’ll see the Click URL variable will be available under the Built-In Variables table.
Create a trigger
First, create a trigger which will only fire when an outbound link is clicked. Click the Triggers menu item and then the New button.
Name your trigger Click - Outbound Link.
Click the ‘Choose a trigger type to begin…’ text and select Just Links in the menu that appears.
We need to have the trigger to fire on outbound link clicks, not all link clicks, so need to select the Some Link Clicks radio button. In the appeared boxes, add a condition where Click URL does not contain store.com. Then save the trigger. Now this created trigger can be used to fire any tags we only want to fire when outbound links are clicked.
Create a tag
Create a new Universal Analytics tag, giving it the name GA Outbound Link Click.
Then enter your Google Analytics property ID, and then change Track Type from Pageview to Event.
Set the event category to Outside Interactions.
Set event action to Outbound Link Clicked.
Set event label to the Click URL variable (click on the brick
icon to the right of the input field for a list of available variables).
Once inserted, the variable name is surrounded by double curly braces. This means this field will be replaced at run-time with
the action value of the clicked URL.
Set the trigger
In the Triggering section, click the pencil icon and select the Click - Outbound Link trigger we created earlier. Then save the tag.
Now you can check that the GTM debugger which shows your tag firing when you click on the links other than store.com.
Subscribe to:
Posts (Atom)