In this tutorial, we will learn about java.sql.SQLTimeoutException Query Timeout
It is always good to do proactive coding. As part of database connection configuration we need to take care of certain parameters
Timeout is one of those properties. If don’t configured well you might get below exception
java.sql.SQLTimeoutException The Query has Timed Out
Root Cause for query timeout
Your application runs a long query with database. you will have this exception.
Solution
- setQueryTimeout
- Sets the number of seconds the driver will wait for a Statement object to execute to the given number of seconds.
- default value is 0. which means infinite
- setSelectMethod cursor
- By setting the property to “cursor,”. you can create a server-side cursor that can fetch smaller chunks of data at a time
- default value is direct.
- setSendStringParametersAsUnicode false
- Set to false string parameters are sent to the server in an ASCII/MBCS format, not in UNICODE
- default value is true