Archive for the ‘Java’ Category

Connection Pool: MySQL Communications link failure

The Problem And The Solution While using a MySQL connection pool in Java, I received a MySQL Communications link failure Exception (see below). In order to solve communication link failure exception: I have removed JDBC property autoReconnect=true and put only the JDBC property autoReconnectForPools=true I have added the connection properties: testOnBorrow testWhileIdle timeBetweenEvictionRunsMillis minEvictableIdleTimeMillis See [...]

Connection Pool: MySQL connection closed exception

The Problem While using a MySQL connection pool in Java, I received a MySQL Connection Closed Exception (see below). The problem was that the JDBC driver was not compatible to the MySQL server version. I have used version 5.05a for both JDBC and MySQL and it solved the problem The problem is that the connection [...]

How To Switch Java in Centos

* If you need to install a new version of java, download the version from java.sun * run /usr/sbin/alternatives to change the default java. If you will run the next command you will see which java versions are available: # /usr/sbin/alternatives –config java There is 1 programs which provide ‘java’. Selection Command ———————————————– *+ 1 [...]

Adding DbUnit to your project

About DbUnit DbUnit is a JUnit extension (also usable with Ant) targeted at database-driven projects that, among other things, puts your database into a known state between test runs. This is an excellent way to avoid the myriad of problems that can occur when one test case corrupts the database and causes subsequent tests to [...]

How to set up a MySQL connection pool in Java

MySQL connection pool A MySQL connection pool is a pool of connections to MySQL database. Opening and maintaining a database connection for each process (or thread), is time costly (connection creation time) and wastes resources (connections). Connection pool increase the performance of (Java) applications that needs to connect to the database by reusing the connections. [...]

How to install ANT on LINUX

Apache Ant is a Java library and command-line tool that help building software. How to install: Create downloads directory if you dont have one Download tar version from http://ant.apache.org/bindownload.cgi Extract Rename the new directory as ant Insert the path into ANT_HOME Update the global PATH variable to include ANT_HOME Run the Ant script fetch.xml to [...]

How to dynamically create an object in Java from a class name given as string format

To create an object dynamically from the class name, you need to use a reflection. If the fully-qualified name of a class is available, it is possible to get the corresponding Class using the static method Class.forName(). However, This cannot be used for primitive types. Having the Class type, you need to use the newInstance() [...]