`

sql socket timeout configuration

 
阅读更多

http://www.cubrid.org/blog/dev-platform/understanding-jdbc-internals-and-timeout-configuration/

 

 jetty jndi

 <Set name="connectionProperties">

<New class="java.util.Properties">

<Call name="setProperty">

             <Arg>oracle.net.CONNECT_TIMEOUT</Arg>

             <!-- ms -->

             <Arg>60000</Arg>

        </Call>

        <Call name="setProperty">

             <Arg>oracle.jdbc.ReadTimeout</Arg>

             <!-- ms -->

             <Arg>60000</Arg>

        </Call>

</New>

</Set>

 

Tomcat jndi config

 <Resource auth="Container" name="jdbc/aaa" driverClassName="oracle.jdbc.driver.OracleDriver" maxActive="30" maxIdle="4" maxWait="1500" 

              removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"

username="ad" password="aaa" type="javax.sql.DataSource" url="jdbc:oracle:thin:@10.2.2.2:1521:uat" testOnBorrow="true" validationQuery="SELECT 1 FROM DUAL" connectionProperties="{oracle.jdbc.ReadTimeout=60000,oracle.net.CONNECT_TIMEOUT=60000}"/>

 

JDBC driver type 4 uses the socket to connect to the DBMS, and the connection timeout process between the application and the DBMS is not carried out by the DBMS.

Socket timeout value for JDBC driver is necessary when the DBMS is terminated abruptly or an network error has occured (equipment malfunction, etc.). Because of the structure of TCP/IP, there are no means for the socket to detect network errors. Therefore, the application cannot detect any disconnection with the DBMS. If the socket timeout is not configured, then the application may wait for the results from the DBMS indefinitely. (This connection is also called a "dead connection.") To prevent dead connections, a timeout must be configured for the socket. Socket timeout can be configured via JDBC driver. By setting up the socket timeout, you can prevent the infinite waiting situation when there is a network error and shorten the failure time.

It is not recommended to use the socket timeout value to limit the statement execution time. So the socket timeout value must be higher than the statement timeout value. If the socket timeout value is smaller than the statement timeout value, as the socket timeout will be executed first, and the statement timeout value becomes meaningless and will not be executed.

Socket timeout has 2 options listed below, and their configurations vary by driver.

 

  • Timeout at socket connection: Time limit for Socket.connect(SocketAddress endpoint, int timeout)
  • Timeout at socket reading/writing: Time limit for Socket.setSoTimeout(int timeout)

 

By checking the source for CUBRID, MySQL, MS SQL Server (JTDS) and Oracle JDBC, we confirmed that all the drivers we checked use the 2 APIs above.

How to configure SocketTimeout is as explained below.

 

How to configure SocketTimeout is as explained below.

JDBC Driver connectTimeout Default Unit Application Method
socketTimeout Default Unit
MySQL Driver connectTimeout 0 ms

Specify the option in the DriverURL.
Format:
jdbc:mysql://[host:port],[host:port].../[database]
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...

Example:

 
jdbc:mysql://xxx.xx.xxx.xxx:3306/database?connectTimeout=60000&socketTimeout=60000
socketTimeout 0 ms
MS-SQL Driver
jTDS Driver
loginTimeout 0 sec

Specify the option in the DriverURL. Format:
jdbc:jtds:<server_type>://<server>[:<port>][/<database>][;<property>=<value>[;...]]

Example:

 
jdbc:jtds:sqlserver://server:port/database;loginTimeout=60;socketTimeout=60

 

socketTimeout 0 sec
Oracle Thin Driver oracle.net.CONNECT_TIMEOUT 0 ms Not possible with the driverURL. Must be delivered to the properties object via OracleDatasource.setConnectionProperties() API. When DBCP is used, use the following APIs:
  • BasicDatasource.setConnectionProperties()
  • BasicDatasource.addConnectionProperties()
oracle.jdbc.ReadTimeout 0 ms
CUBRID Thin Driver No separate configuration 5,000 ms Not possible with the driverURL. Timeout occurs in 5 seconds.
  • Note 1: When timeout occurs with althost option specified in the URL, it can be connected to the designated host.
  • Note 2: C API can be used to state the login_time option in ms in the URL.
  • Note 1: The default value for connectTimeout and socketTimeout is "0," which means that the timeout does not occur.
  • Note 2: You can also configure through properties without directly using the separate API of DBCP. 
分享到:
评论

相关推荐

    sql.zip_SQL SOCKET_in_vc sql

    在IT行业中,SQL(Structured Query Language)是一种用于管理和处理关系数据库的强大语言,而Socket编程则是一种网络通信技术,常用于实现客户端与服务器之间的数据传输。当你在VC++(Visual C++)环境中结合两者时...

    java.sql.SQLRecoverableException(解决方案).md

    System.out.println("Attempt " + retriesLeft); } } }, 1, 1, TimeUnit.SECONDS); } } return connection; } } ``` 通过这两种方法,可以有效地解决在Java中使用JDBC连接数据库时可能遇到的`...

    揭秘JDBC超时机制完整版

    在应用与数据库间,存在多个级别的timeout,包括socket timeout、statement timeout和transaction timeout。这些timeout层次结构决定了当低级别timeout失效时,高级别timeout可能无法正常工作。例如,如果socket ...

    SQL查询超时的设置方法(关于timeout的处理)

    通过对`connect_timeout`、`interactive_timeout`、`wait_timeout`等参数的调整,可以更好地控制连接的生命周期,防止因长时间无响应导致的问题,并确保系统能够有效地处理各种查询。在进行调整时,务必根据实际情况...

    【ASP.NET编程知识】ASP.NET session.timeout设置案例详解.docx

    在上面的代码中,我们可以看到 `timeout` 属性,该属性用于设置会话超时时间,单位为分钟。默认情况下,该值为 20。 除了在 web.config 文件中设置会话超时时间外,我们还可以在 Global.asax 文件中使用 `Session_...

    sql2000与sql2005的hibernate-configuration

    标题“sql2000与sql2005的hibernate-configuration”涉及的是在Hibernate框架中配置SQL Server 2000和2005数据库的过程。Hibernate是一个流行的Java对象关系映射(ORM)工具,它允许开发人员用Java对象来操作数据库...

    Unity3D教程:用socket来操作sqlserver1

    ### Unity3D教程:使用Socket操作SQLServer #### 一、引言 在Unity3D游戏开发中,经常需要与后端数据库进行交互以实现数据存储、查询等功能。本教程将详细介绍如何使用Socket编程技术来操作SQL Server数据库,并...

    WPF MVVM整套框架+Socket+SQL+ADO+开源代码

    本项目支持多种类型的 SQL 数据库,如 MySQL、SQL Server、Oracle 和 PostgreSQL 等。ADO.NET(应用程序开发对象)是 .NET 框架的一部分,用于与数据库交互。它提供了数据库连接、数据命令、数据适配器等组件,使得...

    timeout.zip

    在IT行业中,"timeout"是一个常见的概念,尤其在编程、网络请求和系统设计等领域。"timeout.zip"这个文件名可能暗示着一个与超时错误相关的压缩包,它可能包含一些日志、源代码、测试数据或者解决问题的文档。下面...

    mysql提示got timeout reading communication packets的解决方法

    MySQL数据库在运行过程中可能会遇到各种错误,其中"Got timeout reading communication packets"是一个常见的错误提示,意味着客户端在尝试读取服务器的通信数据包时超时。这个错误通常与连接的超时设置、网络延迟...

    TCP.rar_TCP 服务器端_socket sql_socket tcp_socket连续_tcp 异步

    关于"socket_sql",这意味着服务器端可能有一个中间层负责将TCP数据流解析为SQL命令,执行命令并返回结果。这可能涉及到对原始TCP数据的解码,创建合适的SQL语句,以及使用`SqlCommand`的`ExecuteReader`或`...

    SQL Server 2017 Administration Inside Out

    Microsoft Press SQL Server 2017 Administration Inside Out

    监听SQL数据库,socket 推送至HTML.zip

    "监听SQL数据库,socket推送至HTML"的主题涉及到两个主要技术领域:数据库监控和Websocket通信。接下来,我们将深入探讨这两个技术及其结合应用。 首先,SQL数据库是用于存储和管理结构化数据的主要工具。在许多...

    sql&socket;控制器

    标题中的“sql&socket;控制器”指的是一个C#开发的应用程序,它整合了SQL数据库(这里具体指MySQL)管理和Socket通信的功能。这个程序的核心是通过Socket接收数据,并将接收到的数据按照预设的规则存储到MySQL数据库...

    SQL_Server 2012 SP4 - Express Edition_ConfigurationFile.rar

    在给定的压缩包 "SQL_Server 2012 SP4 - Express Edition_ConfigurationFile.rar" 中,包含了一个用于静默安装的配置文件 "ConfigurationFile.ini"。 静默安装是一种无需用户交互的安装方式,通过命令行参数和配置...

    说说SQL Server 网络配置

    打开Sql Server Configuration Manager,里面显示了SQL Server的网络配置,这些到底表示什么含义呢?   图一:MSSQLSERVER的协议  这些配置选项,其实是为了保证客户端和数据库服务器能够正确的连接,以便...

    sqlserver-trigger-socket通信

    当我们提到“sqlserver-trigger-socket通信”这个概念时,我们指的是在SQL Server触发器和Socket通信技术之间建立一种交互机制。这种机制能够使得数据库事件触发后,通过Socket通信将事件信息传送到其他系统或者应用...

    MySQL和连接相关的timeout 的详细整理

    MySQL中的各种timeout设置是数据库管理中的重要参数,它们关乎到系统的稳定性和性能。这些timeout值主要涉及连接建立、数据传输以及连接空闲时的管理,确保了资源的有效利用和系统的高效运行。 首先,`slave_...

    总结JDBC连接SQLServer的错误Error establishing socket

    总结JDBC连接SQLServer的错误Error establishing socket

Global site tag (gtag.js) - Google Analytics