I am using JDBCTemplate. For one particular query JDBCTemplate hangs after calling more than 3-4 times, sometimes after 15-20 attempts. I haven’t found any bug in my code.
private String getXXX(String table)
{
System.out.println("Test 1");
final List<String> data = getJdbcTemplate().queryForList(SELECT_TBL_NME,
new Object[] { table }, String.class);
System.out.println("Test 2");
ret = data.size() > 0 ? data.get(0) : null;
return ret;
}
Console hangs at “Test 1” without any error if the function is called more than 15 times or sometimes even after the 3rd or 4th call.
The problem seems to be that you aren’t closing the connections.
The line above will never end because the JdbcTemplate is waiting to get a connection from your db.
So if your db cannot give you a connection your application is waiting, waiting, waiting and it does nothing with the time.
possible fix: Since you are using Spring, check that you aren’t doing operation outside your
queryForListmethod.I had the same problem few months ago because I was calling the ResultSet.getMetaData() outside my
queryForListmethod and that was’t releasing/closing the connection.