使用Hibernate与MySQL时遇到的一个问题,记录下来.
1.错误描述:
警告: SQL Error: 0, SQLState: 08S01
2009-4-13 16:21:23 org.hibernate.util.JDBCExceptionReporter logExceptions
严重: The driver was unable to create a connection due to an inability to establish the client portion of a socket.
This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable.
For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required.
For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).
2009-4-13 16:21:23 org.hibernate.util.JDBCExceptionReporter logExceptions
2.解决方案:
上述问题是在大批量插入数据的情况下出现的,使用的数据源配置如下:
<bean id="dataSource" name="code"><bean id="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource"destroy-method="close"><property name="driverClass"><value>com.mysql.jdbc.Driver</value></property><property name="jdbcUrl"><value>jdbc:mysql://localhost:3306/test</value></property><property name="properties"><props><prop key="c3p0.minPoolSize">2</prop><prop key="c3p0.maxPoolSize">50</prop><prop key="c3p0.timeout">5000</prop><prop key="c3p0.max_statement">100</prop><prop key="c3p0.testConnectionOnCheckout">true</prop><prop key="user">root</prop><prop key="password">123456</prop></props></property></bean>