SQL Server 2000 Driver for JDBC: Connection reset by peer
If you’re using the SQL Server 2000 Driver for JDBC
and Commons DBCP
and you either you see this error in your logs:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Connection reset by peer: socket write error
and / or your application stops functioning after your SQL Server is
restarted or the connection between the your application and the SQL
Server is terminated, then you need to add this to your JDNI setup:
<parameter>
<name>validationQuery</name>
<value>select $somecolumn FROM $sometable</value>
</parameter>
where the value is a query that returns at least one row from your database. According to the documentation
, the validation query is:
“… invoked in an implementation-specific fashion to
determine if an instance is still valid to be returned by the pool. It
will only be invoked on an “activated” instance.”
In my testing, if I add the validationQuery parameter to my JNDI
setup, restart the servlet container (in this case Tomcat), request a
page and then stop SQL Server, an error is returned (as expected).
After starting SQL Server and requesting another page, the application
returns to normal usage (which doesn’t happen if the validationQuery
parameter is not present).
转自:http://cephas.net/blog/2004/07/14/sql-server-2000-driver-for-jdbc-connection-reset-by-peer/
分享到:
相关推荐
此异常通常发生在使用JDBC驱动连接SQL Server数据库并尝试执行某些操作(如分页)时。具体而言,当使用`setFirstResult()`和`setMaxResults()`方法对查询结果集进行限制时,如果结果集被标记为只进(forward-only)...
解决oracle数据库发生'Connection reset by peer' or 'Connection reset'的错误 这边的数据库连接是kettle自带的h2数据库,只要有kettle就有这个数据库,目录位于data-integration\samples\db\,连接方式是 ...
确保项目中包含了c3p0的jar包以及SQL Server 2000的JDBC驱动。 **2. 配置Hibernate** 在`hibernate.cfg.xml`文件中添加以下配置: ```xml <!-- 数据库连接URL --> <property name="connection.url"> jdbc:...
这段代码首先加载了`org.postgresql.Driver`类(即PostgreSQL的JDBC驱动),然后通过`DriverManager.getConnection()`方法建立了一个到指定数据库的连接。 **4. 执行SQL语句** 有了连接后,可以使用`Statement`或`...
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/summer","root", "mysql"); ``` 这里,`com.mysql.jdbc.Driver`是MySQL的JDBC驱动,`jdbc:mysql://localhost:3306/summer`是数据库URL...
如果是 SQL Server,则需要选择 SQL Server 的 JDBC 驱动。 **STEP2:** 连接池连接属性配置。这一阶段主要涉及以下几点: - **连接 URL**:指定数据库的位置,通常包括主机名、端口、数据库实例名等信息。 - **...
Connection con = java.sql.DriverManager.getConnection("jdbc:mysql://127.0.0.1/Test?characterEncoding=utf-8", "root", "root"); ``` 使用`Class.forName`加载MySQL JDBC驱动程序。之后通过`DriverManager....
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; String url = "jdbc:sqlserver://localhost:1433;DatabaseName=kun"; String user = "sa"; String pwd = "sa"; // 加载数据库驱动 Class.forName...
- **`driver-class-name`**:JDBC驱动类名。 - **`url`**:数据库连接URL。 - **`username`**:数据库用户名。 - **`password`**:数据库密码。 - **`initial-size`**:初始连接数。 - **`min-idle`**:最小空闲连接...
* 暂不支持query_expression_options,如:HIGH_PRIORITY/STRAIGHT_JOIN/SQL_SMALL_RESULT/ SQL_BIG_RESULT/SQL_BUFFER_RESULT/SQL_CACHE/SQL_NO_CACHE/SQL_CALC_FOUND_ROW * 暂不支持非SELECT的子查询 * 暂不支持不...
本示例主要讲解了如何使用JSP(JavaServer Pages)结合数据库实现一个简单的用户登录功能。这个程序由四个JSP页面组成,分别是: 1. login.jsp:这是用户登录的页面,用户输入用户名和密码后,通过POST方法提交到...
根据提供的部分内容,“java.sql.SQLException: Already closed.”和“java.sql.SQLException: I/O exception: Connection reset by peer: socket write error”这类异常通常与数据库连接管理不当有关,如连接超时、...
Class.forName("com.mysql.jdbc.Driver"); // 连接数据库 String url = "jdbc:mysql://localhost:3306/mydatabase"; String user = "root"; String password = "password"; conn = DriverManager.get...
Class.forName("com.mysql.jdbc.Driver"); String strConn = "jdbc:mysql://localhost:3306/ent_information"; String strUser = "root"; String strPassword = "root"; Connection conn = DriverManager.get...
Class.forName("com.mysql.jdbc.Driver"); DriverManager.registerDriver(new com.mysql.jdbc.Driver()); // 数据库连接参数 String url = "jdbc:mysql://localhost:3306?useUnicode=true&characterEncoding=...
Class.forName("com.mysql.jdbc.Driver"); String strConn = "jdbc:mysql://localhost:3306/ent_information"; String strUser = "root"; String strPassword = "root"; Connection conn = DriverManager.get...
Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bk", "root", "123456"); PreparedStatement ps = con.prepareStatement("select * from ...
Class.forName(DBDRIVER); Connection conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS); PreparedStatement ps = conn.prepareStatement("SELECT COUNT(*) FROM users WHERE userid=?"); ps....