davioooh
davioooh

Reputation: 24676

Connection exception using Spring JDBC Template

I have a simple Web App developed using Spring and recently I'm having some problems with DB connections. My DB is on MS SQL Server 2005.

To retrieve data I implemented several DAO using JDBCTemplate class provided by the framework.

Sometimes I get this exception:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: StatementCallback; SQL [SELECT [Campaigns].[CampaignID],[CampaignCode],[CampaignType],[StartDate],[EndDate],[Status],[FirstUpdate],[LastUpdate],[FirstUpdateUserID],[LastUpdateUserID],[CampaignDescriptions].[Description] FROM [Campaigns] INNER JOIN [CampaignDescriptions] ON [Campaigns].[CampaignID] = [CampaignDescriptions].[CampaignID] ORDER BY [StartDate] DESC]; Connection reset by peer: socket write error; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset by peer: socket write error
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

the exception seems to occur only when the reported query is executed.

I can't understand what's causing this problem. Any idea?

The method executing the query is:

@Transactional(propagation = Propagation.NEVER)
public Campaign[] getAll() {
    List<Campaign> campList = getJdbcTemplate()
            .query(BASE_QUERY,
                    new CampaignMapper());
    return campList.toArray(new Campaign[0]);
}

where BASE_QUERY is the same in the exception message.

Upvotes: 5

Views: 9472

Answers (1)

Gareth Davis
Gareth Davis

Reputation: 28059

it kinda of smells like a stale connection problem. It might be showing up only in this query if it is quite common or the first to be executed (most of the time).

Things to check:

  • Server side connection timeout
  • Connection pool minium idle timeout
  • Connection pool verify connection before use

Upvotes: 3

Related Questions