java - JTDS - java.sql.SQLException : I/O Error: Connection reset by peer: socket write error

标签 java sql-server sql-server-2012 jtds

我使用的 jTDS 是一个适用于 Microsoft SQL Server (2012) 的开源 100% 纯 Java(类型 4)JDBC 3.0 驱动程序>.

Tomcat 7 - 我在下面有连接池配置

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/webapp">
    <Resource name="jdbc/dbname" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
               username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
               url="jdbc:jtds:sqlserver://localhost;databaseName=dbname;SelectMethod=Cursor"/>
</Context>

有时,我会收到以下异常 - 无法从 sql server 获取连接。不知道什么原因?

java.sql.SQLException: I/O Error: Connection reset by peer: socket write error at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1052) at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:465) at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:777) at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93) at at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662) Caused by: java.net.SocketException: Connection reset by peer: socket write error at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) at java.net.SocketOutputStream.write(SocketOutputStream.java:136) at java.io.DataOutputStream.write(DataOutputStream.java:90) at net.sourceforge.jtds.jdbc.SharedSocket.sendNetPacket(SharedSocket.java:671) at net.sourceforge.jtds.jdbc.RequestStream.putPacket(RequestStream.java:560) at net.sourceforge.jtds.jdbc.RequestStream.flush(RequestStream.java:508) at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1039) ... 8 more 17-Apr-2015 12:00:54 ERROR PatientProcessor:614 - SQLException java.sql.SQLException: Already closed. at org.apache.tomcat.dbcp.dbcp.PoolableConnection.close(PoolableConnection.java:84) at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:181) at at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662

最佳答案

可能检查以下条件:

  1. 执行SQL语句前检查socket或资源池端口是否未关闭。
  2. 检查连接是否未被任何其他进程重置
  3. 检查端口是否未被其他进程或其他执行使用或锁定。
  4. 检查连接池中是否有可用端口。

关于java - JTDS - java.sql.SQLException : I/O Error: Connection reset by peer: socket write error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30206517/

相关文章:

java - 在java中读取大型xls文件(有7-8张,每张有30-40,000行)

java - 使用 Java SDK 获取 couchbase 版本

sql - 使用带有条件逻辑的 T-SQL 来覆盖 SQL Server View 中使用的列值

c# - 使用 Visual Studio 2010 在 Visual C# 应用程序中使用现有的 SSRS 报告

java - ScheduledExecutorService.scheduleAtFixedRate 并将 initialDelay 设置为过去的日期

java - 使用 Netbeans 和 Mac 开发 Java EE Web 应用程序时如何停止 Mac 上的 Glassfish 服务器?

sql-server - 传递变量 mssql 时列名无效

c# - 为每个查询创建新的 SQL 连接是否有优势?

sql-server - SQL 日期时间比较

macos - Jetbrains 0xDBe : Connecting to SQL Server using Windows Authentication?