Oracle PL/SQL – ACOS 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

Java – How to print a Pyramid

A Java example to print half and full pyramid, for fun. CreatePyramid.java package com.mkyong; import java.util.Collections; public class CreatePyramid { public static void main(String[] args) { int rows = 5; System.out.println("\n1. Half Pyramid\n"); for (int i = 0; i < rows; i++) { for (int j = 0; j <= i; j++) { System.out.print("*"); } …

Read more

Oracle PL/SQL – ASIN 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 – Before DELETE Trigger 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

PDFBox – How to read PDF file in Java

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

Python – How to print a Pyramid

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

Oracle PL/SQL – DROP function example

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 – Check the Trigger status

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 – Before UPDATE Trigger example

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 – Enable and Disable Triggers

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 – Before INSERT Trigger example

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

cURL – PUT request examples

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 – DELETE request examples

To send a DELETE request, uses cURL -X DELETE Terminal $ curl -X DELETE http://localhost:8080/user/100 The above example will delete a user where user id is 100. References cURL official website cURL – POST request examples

How to tell Maven to use Java 8

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

Oracle PL/SQL – After INSERT Trigger example

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

Spring Boot and Mustache – default value

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 Hello World Example – Mustache

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

Apache Solr Hello World Example

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

Java – Convert comma-separated String to a List

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 – How to shuffle an ArrayList

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

Spring MVC – How to get client IP address

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

Java 8 Streams map() examples

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

Oracle PL/SQL – After UPDATE Trigger example

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

Java 8 Tutorials

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.lang.NoClassDefFoundError: com/fasterxml/jackson/annotation/JsonMerge

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

Spring Boot + Spring Data + Elasticsearch example

In this article, we will discuss about “How to create a Spring Boot + Spring Data + Elasticsearch Example”. Tools used in this article : Spring Boot 1.5.1.RELEASE Spring Boot Starter Data Elasticsearch 1.5.1.RELEASE Spring Data Elasticsearch 2.10.RELEASE Elasticsearch 2.4.4 Maven Java 8 Note SpringBoot 1.5.1.RELEASE and Spring Data Elasticsearch 2.10.RELEASE supports only ElasticSearch 2.4.0. …

Read more

Spring Boot Tutorials

Spring Boot makes it quick and easy to create a Spring based applications. Spring Boot 3 minimum supported versions: Spring Framework 6 Java 17 Kotlin 1.6 Jakarta EE 9 (jakarta.*) Maven 3.6.3 or later Gradle 7.x (7.5 or later) and 8.x Spring Boot 3 supports the following embedded servlet containers: Tomcat 10.1, Servlet 6.0 Jetty …

Read more

Spring Boot – Profile based properties and yaml example

In Spring Boot, it picks .properties or .yaml files in the following sequences : application-{profile}.properties and YAML variants application.properties and YAML variants Note For detail, sequence and order, please refer to this official Externalized Configuration documentation. Tested : Spring Boot 2.1.2.RELEASE Maven 3 1. Project Structure A standard Maven project structure. 2. @ConfigurationProperties Read the …

Read more

ElasticSearch Hello World Example

ElasticSearch is an Open-source Enterprise REST based Real-time Search and Analytics Engine. It’s core Search Functionality is built using Apache Lucene, but supports many other features. It is written in Java Language. It supports Store, Index, Search and Analyze Data in Real-time. Like MongoDB, ElasticSearch is also a Document-based NoSQL Data Store. Note ElasticSearch website: …

Read more

Spring Boot Profiles example

In this article, we will show you how to use @Profile in Spring Boot and also how to test it. Tested with : Spring Boot 2.1.2.RELEASE Maven 3 1. Project Structure A standard Maven project structure. 2. Project Dependency pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>spring-boot-profile</artifactId> <packaging>jar</packaging> <name>Spring Boot Profiles Example</name> …

Read more

Spring Boot Test – How to disable DEBUG and INFO logs

Run the Spring Boot integration test or unit test, many annoying DEBUG and INFO logs are displayed in the console. P.S Tested with Spring Boot 2 Console 2019-03-04 13:15:25.151 INFO — [ main] .b.t.c.SpringBootTestContextBootstrapper : 2019-03-04 13:15:25.157 INFO — [ main] o.s.t.c.support.AbstractContextLoader : 2019-03-04 13:15:25.158 INFO — [ main] t.c.s.AnnotationConfigContextLoaderUtils : 2019-03-04 13:15:25.298 INFO — …

Read more

Gradle is not sync with IntelliJ IDEA

Make some changes in the build.gradle file, but the changes never apply or sync to the IDEA (Tested with 2016.3) 1. Using IDEA plugin build.gradle apply plugin: ‘java’ apply plugin: ‘idea’ apply plugin: ‘org.springframework.boot’ 2. Make changes and issue the Gradle clean and idea command. Console $ gracle clean idea $ gradle cleanIdea idea $ …

Read more