JTDS - java.sql.SQLException: I/O Error: Connection reset by peer: socket write error
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30206517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JTDS - java.sql.SQLException: I/O Error: Connection reset by peer: socket write error
提问by arjun
I'm using jTDS
is an open source 100% pure Java (type 4) JDBC 3.0
driver for Microsoft SQL Server (2012)
.
我使用的jTDS
是一个开源的 100% 纯Java (type 4) JDBC 3.0
驱动程序,用于Microsoft SQL Server (2012)
.
Tomcat 7
- I have Connection Pool configuration below
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>
Sometimes, I'm getting the below exception - Unable to get an connection from sql server. I don't know the reason why?
有时,我收到以下异常 - 无法从 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
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:已经关闭。在 org.apache.tomcat.dbcp.dbcp.PoolableConnection.close(PoolableConnection.java:84) 在 org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:181) 在 java.util。
采纳答案by Jagadish Sharma U
Probably Check the following conditions:
大概检查以下条件:
- Check whether the socket or the resource pool port is not closed before the execution of the SQL statement.
- Check whether connection is not reset by any other process
- Check whether the port is not being used by or locked other process or other execution.
- Check whether the there is any available port in the pool of connections.
- 执行SQL语句前检查socket或资源池端口是否关闭。
- 检查连接是否没有被任何其他进程重置
- 检查端口是否未被其他进程或其他执行使用或锁定。
- 检查连接池中是否有任何可用端口。
回答by arjun
Finally I am able to find the reason for getting this error. It is because, After restarting the database server the tomcat server is not restarted (so it remains alive even at the time of restarting the database). Hence the connection in the pool gets invalid. So when the web page tries to create database connection for the first time this error prompts, and during the next attempt it will get valid connection from connection pool as the application server identifies its connections are invalid, so it gets a pool of new connections.
最后,我能够找到出现此错误的原因。这是因为,重新启动数据库服务器后,tomcat 服务器没有重新启动(因此即使在重新启动数据库时它也保持活动状态)。因此池中的连接无效。所以当网页第一次尝试创建数据库连接时会提示这个错误,下次尝试时会从连接池中获取有效连接,因为应用服务器识别出它的连接是无效的,所以它会获取一个新连接池。