see binding parameters in jpa query
What would the world look like if log was not created for us – I ask, and you say nothing! You right, there is also another world
Getting back from the crazy thoughts, there is a config spring allows us to see the SQL statements that the JPA is doing behind the scenes..
In you application.yml file
Will show the sql statements on your logs. But it will show with ? for the values used.
To see those values also along with the query add the following on the application file.
That is it!
Accessing Docker Postgres in the host application
Accessing docker postgres is was easier with right commands. Docker has been a life saver for most of us – no doubt on that. We can do any kind of software interaction from host machine or from other docker container with bliss.
Once you have the docker postgres up and running, access docker postgres and use it for multiple of your projects. Here I will show how to access docker postgres from host machine. That is the same thing as any other app to access it as well.
Continue reading Accessing Docker Postgres from host application →
Limit BigDecimal to n places only
In java, when you are working with currency and other important precision based calculation, you will use Big Decimal. In some cases you might want to round the number to two (2) decimal places only or, lets say, to n, decimal places.
When to use limited decimal places
There are a couple of cases where you need to round or just to limit the number of decimal places. Once example is when you are working on the currency, after conversion, you may get a long decimal and in that case – rounding will be necessary.
Using big decimal functions for rounding the numbers
BigDecimal bill = new BigDecimal("23.9876546");
The above will be produce
23 this is because of the flag passed to it of
RoundingMode.DOWN. There are other important flags that needs to be passed when rounding.
All the flags are here.
When working on spring framework, you might get this error specially on eclipse. I am assuming you are working on maven and eclipse environment.
ClassNotFound exception is a bit self explanatory that eclipse could not find the mentioned class
web.xml file for the spring configuration might look like
With this, you might have similar file like
application-context in the WEB-INF path
How to fix ClassNotFoundException for ContextLoaderList
The problem will during deployment. It is not basically compile time error. It is rather runtime error.
So, we have to make sure the jar responsible for this class is available in the classpath that eclipse is reading.
Pom dependency check
Make sure you have the same/similar configuration as the one listed below on your pom file.
You can have the right version for your spring in the parameter section or you can just replace it with the current version you have.
Using Deployment Assembly fix in eclipse
As we know, it is a deployment time problem, hence we have to tell the assembly where it can get its dependencies.
Right click on the project
Go to/search for Deployment Assembly
Click on Add
Select on Java Build path entries
Select all the maven dependencies
Clean and build the project
Either of the above methods should fix the problem
The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path error in java webapp
If you are using eclipse, this might be due to project facet, right click on the project, go to project facet and select Runtimes and check the server you have configured.
if the app you are running is not spring or other web app framework that already comprised of servlet, then you need to add servlet to the build path.
You can add the servlet either through dependency management tools like gradle and maven or you can add it to the project lib file and compile it.
Also, you can add the dependency to servlet in your pom and get rid of the problem.
String Permutation Problem
The algorithm problem goes something like this:
If you are given a character and its possible substitution set, then write a function that would print all the permutation of its characters.
Given word “java”
Substitution Set =>
j [“J”, “7”]
a [“@”, “J”, “9”]
v [“V”, “^”]
Based on this, the possible permutations could be: J@V@, 7JV9..
Here is my approach using java
Continue reading String Ordered Permutation Algorithm Problem →
How to set JAVA_HOME ON MAC OSX computer
java_home as environment variable might be almost required especially when you use frameworks. Frameworks like
axis2 web server and others. Also some code editors require that too.
What is environment variable
Those are variables that would allow you to execute command line actions from any directory, basically from everywhere.
The simplest example is using
java -version. In this case, if you don’t have explicit environment variable on where to look for, it requires you to either be in the java folder or to fully list the whole path till bin folder.
Setting JAVA_HOME in mac osx
The first part is to make sure you have java installed in your machine.
If this is giving you an output with the version, then it means java is installed, otherwise, you should first install it.
The following task will be to find out where the binary files are located.
Click the apple icon on the left top corner of your mac and select system preferences..
And from there click Java and you will get the path information from there.
Once you got where the java is located, usually on
Open the bash properties file
And add the java path here
export JAVA_HOME=export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
The above would be what it would look like fro jkd 1.8 on my El Capitan macbook pro.
hello world weblogic app server
There are lots of application servers for java and oracle weblogic is one of them. As of this writing the current and latest weblogic server is 12c
I will show a simple hello world tutorial on weblogic. The tutorial is for beginners of weblogic server.
This hello world weblogic tutorial assumes you have java skill already.
Installing weblogic server
First thing first, lets install and configure weblogic server
Continue reading hello world weblogic – hello world tutorial on weblogic →
How to pass complex object parameter to jersey
In this tutorial, I will try to show how to pass composite object as a parameter to jersey’s endpoint java application.
It seems like you are working on RESTful API based java application. In that case, chances are high that you are working with jersey.
If you are not familiar with jersey, jersey is an implementation of JAX-RS APIs. Hence, it is a seamless framework by which API based java projects can be implemented.
As of this writing, the current version of jersey is 2.23.
Continue reading Passing composite object parameter to jersey in Restful Java web →
Hello World Beginner Tutorial using J2EE and Maven
This is part two of J2EE application with maven continued from Part One.
If you haven’t accomplished J2EE with Maven tutorial, please first complete it by going here
Maven relies highly on the pom.xml file that we would put on the project root folder. Lets do that.
In this part of J2EE tutorial and Maven tutorial, we will proceed from creating a pom.xml file which is the heart of maven.
3 Create the pom and compile the project using maven.
3.a put the following pom file in the MavenEclipseJ2EE directory.
Continue reading J2EE Maven Eclipse Hello World Tutorial Part Two →