MySQL MariaDB utf8 to utf8mb4

Dec 25, 2017 1 min.

Change server settings Refer: on AWS RDS a parameter group needs to be created to apply above settings: refer: Change database Run this SQL for each database: ALTER DATABASE mydb CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci; Change size of indexed columns Reduce the length of indexed columns with utf8mb4 from 256 to 190 because index with 4byte utf8mb4 have issues ALTER TABLE mydb.mytable MODIFY COLUMN mycolumn varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; Change Tables Run this SQL for each table:

JEE Container Managed Transaction

Dec 25, 2017 1 min.

Transaction Attribute Client’s Transaction Business Method’s Transaction Required None T2 T1 T1 RequiresNew None T2 T1 T2 Mandatory None error T1 T1 NotSupported None None T1 None Supports None None T1 T1 Never None None T1 Error Container Manager Transaction

Java Time Difference

Dec 24, 2017 2 min.

Time difference can be calculated by subtracting the milliseconds. And then milliseconds can be converted into different Units using TimeUnit. e.g. TimeUnit.MILLISECONDS.toSeconds(1000) will give 1 because 1 second equivalent to 1000 millisecons. Following sample gives a example of finding difference between two dates and converting them into different units import java.util.Date; import java.util.concurrent.TimeUnit; public class TimeDifference { public static void main(String[] args) { Date date1 = new Date(System.currentTimeMillis() - (24 * 60 * 60 * 1000)); Date date2 = new Date(); long timeDifferenceInDays = TimeUnit.

JAXRS Rest Client

Dec 20, 2017 1 min.

Option 1 : Using interface proxy import; import; import; import; import; import org.apache.cxf.jaxrs.client.JAXRSClientFactory; import org.apache.cxf.jaxrs.client.WebClient; import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; public class RestClient { public static void main(String[] args) { final MyApiClient client = JAXRSClientFactory.create("<http://localhost:8080/api>", MyApiClient.class); final HTTPClientPolicy clientPolicy = WebClient.getConfig(client).getHttpConduit().getClient(); clientPolicy.setConnectionTimeout(15 * 1000); clientPolicy.setReceiveTimeout(15 * 1000); final Response response = client.hello("your-authorization-token", "javawiki"); System.out.println("Response Status: " + response.getStatus()); } } @Path("/testapi") public interface MyApiClient { @PUT @Path("/hello") Response hello(@HeaderParam("AUTHORIZATION") String authorization, @FormParam("name") String name); } Option 2: Direct client import javax.

Java get hostname and IP address

Dec 19, 2017 1 min.

Use to get hostname or IP Address To get local hostname or IP import; public class LocalIPGetter { public static void main(String[] args) throws Exception { InetAddress inetAddress = InetAddress.getLocalHost(); // Get Hostname System.out.println(inetAddress.getHostName()); // Get IP Address System.out.println(inetAddress.getHostAddress()); } } $javac $java LocalIPGetter mytestpc To get remote hostname or IP import; public class RemoteIPGetter { public static void main(String[] args) throws Exception { InetAddress inetAddress = InetAddress.

MySQL MariaDB Set utf8mb4 as default charset

Nov 22, 2017 2 min.

By default charset is set to to latin1 and utf8. This can be checked by executing the following command MariaDB [(none)]> SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%'; +--------------------------+-------------------+ | Variable_name | Value | +--------------------------+-------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | collation_connection | utf8_general_ci | | collation_database | latin1_swedish_ci | | collation_server | latin1_swedish_ci | +--------------------------+-------------------+ To set the charset as utf8mb4 do the following steps:

Install Mariadb in Aws Ec2

Nov 22, 2017 2 min.

These steps can be used install mariadb on any Ubuntu based Linux system (local desktop, aws ec2, etc.) Install MariaDB Execute the following commands: curl -sS | sudo bash sudo apt install mariadb-server During this setup, it will ask for root password. Enter and keep a note of it. Install a specific version curl -sS | sudo bash -s -- --mariadb-server-version="mariadb-10.3" sudo apt install mariadb-server For NON LTS version Goto this link: https://downloads.

Git Squash

Nov 10, 2017 1 min.

Option 1 to squash last two commits git rebase -i HEAD~2 This will open editor where you can choose which commit to keep and which to squash. Also you have option to rewrite messages. Option 2 Reset and commit again: git reset --soft HEAD~2 git commit -m "New message for the combined commit" public class Test { public static void main(String[] args) { System.out.println("hello"); } } <section id="main"> <div> <h1 id="title">{{ .

TomEE datasource password encryption

Nov 9, 2017 1 min.

Execute the following command to get the cipher: cd <<tomcat_home>>/bin cipher <<orginal password>> e.g. cipher Passw0rd This will give the cipher something like below xMH5uM1V9vQzVUv5LG7YLA== Use this cipher in the resources.xml with the prefix ‘cipher:Static3DES:’ as given below <resources> <Resource id="jdbc/myDS" type="javax.sql.DataSource"> password = cipher:Static3DES:xMH5uM1V9vQzVUv5LG7YLA== </Resource> </resources> alternatively you can give as below <resources> <Resource id="jdbc/myDS" type="javax.sql.DataSource"> password = xMH5uM1V9vQzVUv5LG7YLA== PasswordCipher = Static3DES </Resource> </resources>

Ubuntu Netbeans.desktop file

Nov 8, 2017 1 min.

File: /usr/share/applications/netbeans.desktop [Desktop Entry] Encoding=UTF-8 Name=NetBeans IDE 8.2 Comment=The Smarter Way to Code Exec=/apps/netbeans-8.2/bin/netbeans Icon=/apps/netbeans-8.2/nb/netbeans.png Categories=Application;Development;Java;IDE Version=1.0 Type=Application Terminal=0 StartupNotify=true StartupWMClass=NetBeans IDE 8.2