Just would like to remind anyone who refering to both Remote Access To MySQL Database and Setup Java, Tomcat, MySQL on Ubuntu (JSP Hosting), do remember to change the datasource property which defined via JNDI.
If you are attempting to connect to the database which sit on localhost or other host, make sure the JDBC driver URL is defined exact same on both JNDI and my.cnf. So, the JNDI would able to point to the right host where the database is sit.

Else not, your web application would not able to connect to the database and you will get error similar as below:
javax.servlet.ServletException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Server connection failure during transaction. Due to underlying exception: 'java.net.ConnectException: Connection refused'.Attempted reconnect 3 times. Giving up.)"
If you are attempting to connect to the database which sit on localhost or other host, make sure the JDBC driver URL is defined exact same on both JNDI and my.cnf. So, the JNDI would able to point to the right host where the database is sit.

Else not, your web application would not able to connect to the database and you will get error similar as below:
javax.servlet.ServletException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Server connection failure during transaction. Due to underlying exception: 'java.net.ConnectException: Connection refused'.Attempted reconnect 3 times. Giving up.)"