You should have a read of derby pitfalls in it there are some common pitfalls, the one you are interested in is:
"Executing a Statement automatically closes any existing open ResultSet generated by an earlier execution of that Statement. If threads share Statements, one thread could close another's ResultSet. In many cases, it is easier to assign each thread to a distinct Connection. "
Ok so the problem with your code is DatatTransaction.java, change the code by removing the static variable connection and add this method:
public final Connection getConnection()
{
Connection conn = null;
try
{
conn = dataSource.getConnection();
}
catch (SQLException e)
{
System.out.println("Could not connect to the database msg :" + e.getMessage());
}
return conn;
}
Now it will no longer give any problem (by the way, if you comment the System.out.println() in your example you will see more quickly and more often the concurrency errors which are otherwise mitigated by the time needed to print to the console).
As for the "exceptionorg.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object " that's because you are not closing the resources correctly by commenting the close() methods, so you quickly run out of connections in the pool.