Edit this file /private/etc/hosts. Terminal $ sudo nano /private/etc/hosts ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost 127.0.0.1 mkyong-mac 198.x.x.x linode-bot1 1.2.3.4 www.google.com References What is the difference between […]

Read more How to edit hosts file on Mac OSX

Review the server environment, we need to allow Server B to access the Server A MongoDB database. Server A – MongoDB server Private IP – 192.168.162.129 / 17 Server B – Application Server Private IP – 192.168.204.205 / 17 Update the bind_ip, but unable to start mongod process anymore. /etc/mongod.conf #$ vim /etc/mongod.conf # Listen […]

Read more MongoDB – bind() failed errno:99 Cannot assign requested address for socket

Upgraded MongoDB and unable to start the mongod process, review the /var/log/mongodb/mongod.log file, and found the following error messages : Terminal 2017-08-24T03:57:21.289-0400 I CONTROL [initandlisten] MongoDB starting : pid=31927 port=27017 dbpath=/var/lib/mongodb3 64-bit host=hcompass 2017-08-24T03:57:21.289-0400 I CONTROL [initandlisten] db version v3.2.16 2017-08-24T03:57:21.289-0400 I CONTROL [initandlisten] git version: 056bf45128114e44c5358c7a8776fb582363e094 2017-08-24T03:57:21.289-0400 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t […]

Read more MongoDB – Failed to unlink socket file /tmp/mongodb-27017

The ALTER FUNCTION statement explicitly recompile a standalone function. Sometimes, ALTER TABLE on the table being used in function will cause the function becomes INVALID, we need to recompile (alter function) it to make it VALID again. 1. ALTER function example First, we will create table test_alter, function get_max_amount. In this function, we are using […]

Read more Oracle PL/SQL – ALTER function example

The ACOS() function returns the arc cosine of input n, the input n must be in the range of -1 to 1. The function will return a value in the range of 0 to pi, expressed in radians. ACOS function examples SELECT ACOS(.2) FROM DUAL; — output 1.36943840600456582777619613942212803186 SELECT ACOS(-.4) FROM DUAL; — output 1.98231317286238463861605958925708704694 […]

Read more Oracle PL/SQL – ACOS function example

The ASIN() function returns arc sine of input n, the input n must be in the range of -1 to 1. The function will return a value in the range of -pi/2 to pi/2, expressed in radians. ASIN function examples SELECT ASIN(.25) FROM DUAL; — output 0.25268025514207865348565743699370756609 SELECT ASIN(-.5) FROM DUAL; — output -0.52359877559829887307710723054658381405 SELECT […]

Read more Oracle PL/SQL – ASIN function example

This article shows you how to use BEFORE DELETE TRIGGER, it will fire before the delete operation is executed. In real life scenarios, it is mostly used for purposes like: Restrict invalid DELETE operation. Delete data from another table. 1. Restrict invalid DELETE operation In this example, We have two tables item_details and order_details. The […]

Read more Oracle PL/SQL – Before DELETE Trigger example

This article shows you how to use Apache PDFBox to read a PDF file in Java. 1. Get PDFBox pom.xml <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfbox</artifactId> <version>2.0.6</version> </dependency> 2. Print PDF file Example to extract all text from a PDF file. ReadPdf.java package com.mkyong; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.text.PDFTextStripper; import org.apache.pdfbox.text.PDFTextStripperByArea; import java.io.File; import java.io.IOException; public class ReadPdf { […]

Read more PDFBox – How to read PDF file in Java

A simple Python example to print half and full pyramid, just for fun. def half_pyramid(rows): print(‘Half pyramid…\n’) for i in range(rows): print(‘*’ * (i+1)) def full_pyramid(rows): print(‘\nFull pyramid…\n’) for i in range(rows): print(‘ ‘*(rows-i-1) + ‘*’*(2*i+1)) def inverted_pyramid(rows): print(‘\nInverted pyramid…\n’) for i in reversed(range(rows)): print(‘ ‘*(rows-i-1) + ‘*’*(2*i+1)) half_pyramid(5) full_pyramid(5) inverted_pyramid(5) Output Half pyramid… * […]

Read more Python – How to print a Pyramid

This article shows you how to use DROP FUNCTION to delete a function from Oracle database. 1. DROP function example 1.1 Create a function get_current_month. Then we will delete the function using DROP FUNCTION statement. –Creating function CREATE OR REPLACE FUNCTION get_current_month RETURN VARCHAR2 IS curr_month VARCHAR2(10); BEGIN SELECT to_char(sysdate, ‘MONTH’) INTO curr_month FROM dual; […]

Read more Oracle PL/SQL – DROP function example

Check the USER_TRIGGERS table, you can get the Trigger status easily : — display all triggers for users SELECT TRIGGER_NAME,STATUS FROM USER_TRIGGERS; — display status for a specified trigger SELECT TRIGGER_NAME,STATUS FROM USER_TRIGGERS WHERE TRIGGER_NAME = ‘TRIGGER_NAME’; SELECT TRIGGER_NAME,STATUS FROM USER_TRIGGERS WHERE TRIGGER_NAME IN(‘TRIGGER_NAME_A’, ‘TRIGGER_NAME_B’); Sample data. TRIGGER_NAME STATUS TRIGGER_NAME_A ENABLED TRIGGER_NAME_B DISABLED TRG_BEFORE_EMP_UPDATE ENABLED […]

Read more Oracle PL/SQL – Check the Trigger status

This article shows you how to use BEFORE UPDATE TRIGGER, it’s fire before the update operation is executed. In real life scenarios, it is mostly used for purposes like: Data validation Update values automatically Data logging, or auditing 1. Data Validation Suppose some companies have job openings and already having application data and the criteria […]

Read more Oracle PL/SQL – Before UPDATE Trigger example

This article shows you how to use ALTER TRIGGER and ALTER TABLE to enable and disable triggers. — enable / disable a trigger ALTER TRIGGER trigger_name ENABLE; ALTER TRIGGER trigger_name DISABLE; — enable / disable all triggers for a specific table ALTER TABLE table_name ENABLE ALL TRIGGERS; ALTER TABLE table_name DISABLE ALL TRIGGERS; 1. Table […]

Read more Oracle PL/SQL – Enable and Disable Triggers

This article shows you how to use BEFORE INSERT TRIGGER, it’s fire BEFORE an INSERT operation is executed. In real life scenarios, it is mostly used for purposes like Data validation Update values automatically (e.g CREATED_BY, CREATION_DATE etc) 1. Table Create a employee_details, we will try to insert different values into this table and observe […]

Read more Oracle PL/SQL – Before INSERT Trigger example

Jacoco is used to measure the code coverage of application. In this tutorial we will understand how to configure Jacoco in maven and how to use Jacoco to see code coverage report. Technologies Used: Eclipse Mars Maven 3.3.9 Java 8 1. Eclipse Create Maven Java Project 1.1 In Eclipse create a Maven project File->New->Project->Maven Project, […]

Read more JaCoCo Java Code Coverage + Maven example

Example to use cURL -X PUT to send a PUT (update) request to update the user’s name and email. Terminal $ curl -X PUT -d ‘name=mkyong&[email protected]’ http://localhost:8080/user/100 If the REST API only accepts json formatted data, try this Terminal $ curl -X PUT -H "Content-Type: application/json" -d ‘{"name":"mkyong","email":"[email protected]"}’ http://localhost:8080/user/100 References cURL official website cURL – […]

Read more cURL – PUT request examples

In pom.xml, defined this maven.compiler.source properties to tell Maven to use Java 8 to compile the project. 1. Maven Properties Java 8 pom.xml <properties> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> </properties> Java 7 pom.xml <properties> <maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.source>1.7</maven.compiler.source> </properties> 2. Compiler Plugin Alternative, configure the plugin directly. pom.xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> […]

Read more How to tell Maven to use Java 8

This article shows you how to use AFTER INSERT TRIGGER, it will fire after the insert operation is executed. 1. After INSERT Trigger In this example, if a new user is created in user_details, but fields like passport_no or driving_license_no is missing, a new record will be inserted into user_reminders via ‘after insert’ trigger on […]

Read more Oracle PL/SQL – After INSERT Trigger example

In Spring Boot + Mustache template environment, if we didn’t assign a value to a {{variable}} on the Mustache’s page, the jmustache will throws the following error messages : com.samskivert.mustache.MustacheException$Context: No method or field with name ‘variable’ on line xx at com.samskivert.mustache.Template.checkForMissing(Template.java:316) ~[jmustache-1.13.jar:na] at com.samskivert.mustache.Template.getValue(Template.java:224) ~[jmustache-1.13.jar:na] at com.samskivert.mustache.Template.getValueOrDefault(Template.java:269) ~[jmustache-1.13.jar:na] P.S Tested with Spring Boot 1.5.2.RELEASE […]

Read more Spring Boot and Mustache – default value

A Spring Boot web application example, using embedded Tomcat + Mustache template engine, and package as an executable JAR file. Technologies used : Spring Boot 1.5.2.RELEASE Spring 4.3.7.RELEASE jmustache 1.13 Thymeleaf 2.1.5.RELEASE Tomcat Embed 8.5.11 Maven 3 Java 8 Note Spring Boot uses jmustache to integrate Mustache as template engine. 1. Project Directory 2. Project […]

Read more Spring Boot Hello World Example – Mustache

Apache Solr is an Open-source REST-API based Enterprise Real-time Search and Analytics Engine Server from Apache Software Foundation. It’s core Search Functionality is built using Apache Lucene Framework and added with some extra and useful features. It is written in Java Language. SOLR stands for Searching On Lucene w/Replication. It’s main functionalities are indexing and […]

Read more Apache Solr Hello World Example

Java examples to show you how to convert a comma-separated String into a List and vice versa. 1. Comma-separated String to List TestApp1.java package com.mkyong.utils; import java.util.Arrays; import java.util.List; public class TestApp1 { public static void main(String[] args) { String alpha = "A, B, C, D"; //Remove whitespace and split by comma List<String> result = […]

Read more Java – Convert comma-separated String to a List

In Java, you can use Collections.shuffle to shuffle or randomize a ArrayList TestApp.java package com.mkyong.utils; import java.util.Arrays; import java.util.Collections; import java.util.List; public class TestApp { public static void main(String[] args) { List<String> list = Arrays.asList("A", "B", "C", "D", "1", "2", "3"); //before shuffle System.out.println(list); // again, same insert order System.out.println(list); // shuffle or randomize Collections.shuffle(list); […]

Read more Java – How to shuffle an ArrayList

In Spring framework, you can @Autowired a HttpServletRequest in any Spring managed bean directly, and later get the client’s IP address from the request headers WebUtils.java package com.mkyong.web; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; @Component public class WebUtils { private HttpServletRequest request; @Autowired public void setRequest(HttpServletRequest request) { this.request = request; } private static String […]

Read more Spring MVC – How to get client IP address

In Java 8, stream().map() lets you convert an object to something else. Review the following examples : 1. A List of Strings to Uppercase 1.1 Simple Java example to convert a list of Strings to upper case. TestJava8.java package com.mkyong.java8; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class TestJava8 { public static void […]

Read more Java 8 Streams map() examples

This article shows you how to use AFTER UPDATE TRIGGER, it will fire after the update operation is executed. 1. Logging example In this example, after each update on ‘SALARY’ column of employee_salary, it will fire a ‘after update’ trigger and insert the new updated data into a employee_salary_log table, for audit purpose. 1.1 Create […]

Read more Oracle PL/SQL – After UPDATE Trigger example

A series of Java 8 tips and examples, hope you like it. FAQs Some common asked questions. Java 8 forEach examples Java 8 Convert List to Map Java 8 Lambda : Comparator example Java 8 method references, double colon (::) operator Java 8 Streams filter examples Java 8 Streams map() examples 1. Functional Interface Java […]

Read more Java 8 Tutorials

Run a Jackson related project and hits the following JsonMerge not found error. Console java.lang.NoClassDefFoundError: com/fasterxml/jackson/annotation/JsonMerge at com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector.<clinit>(JacksonAnnotationIntrospector.java:50) ~[jackson-databind-2.9.0.pr1.jar:2.9.0.pr1] at com.fasterxml.jackson.databind.ObjectMapper.<clinit>(ObjectMapper.java:292) ~[jackson-databind-2.9.0.pr1.jar:2.9.0.pr1] at com.hostingcompass.core.utils.PrintUtils.<clinit>(PrintUtils.java:9) ~[main/:na] at com.hostingcompass.app.run.TurtleApp.run(TurtleApp.java:25) ~[main/:na] at com.hostingcompass.app.Main.run(Main.java:42) [main/:na] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:747) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] at com.hostingcompass.app.Main.main(Main.java:34) [main/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) […]

Read more java.lang.NoClassDefFoundError: com/fasterxml/jackson/annotation/JsonMerge