hibernate 查询mysql数据库出错

08-05-28 talkboy
我的环境:winXP spring 2.0+hibernate 3.0 +mysql5.0+jdk1.5.0_07

代码如下:

package com.nxyl.system.file;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.nxyl.food.manage.service.ProductService;

public class Test {

/**

* @param args

*/

public static void main(String[] args) {

// TODO 自动生成方法存根

ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

//ImportService importService = (ImportService)context.getBean("importService");

ProductService productService =(ProductService)context.getBean("productService");

for(int i=0;i<20000;i++)

{

productService.getProduct("2100041730015");

System.out.println(i);

}

}

}

talkboy
2008-05-28 18:35
错误如下:

WARN - SQL Error: 0, SQLState: 08S01

ERROR - Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException

MESSAGE: java.net.BindException: Address already in use: connect

STACKTRACE:

java.net.SocketException: java.net.BindException: Address already in use: connect

at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)

at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)

at com.mysql.jdbc.Connection.createNewIO(Connection.java:2641)

at com.mysql.jdbc.Connection.<init>(Connection.java:1531)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)

at java.sql.DriverManager.getConnection(DriverManager.java:525)

at java.sql.DriverManager.getConnection(DriverManager.java:140)

at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:291)

at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:277)

at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:259)

at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:240)

at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)

at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)

at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)

at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)

at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)

at org.hibernate.loader.Loader.doQuery(Loader.java:673)

at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)

at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)

at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)

at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)

at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)

at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)

at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)

at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)

at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:195)

at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)

at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)

at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)

at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)

at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:470)

at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)

at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:464)

at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:458)

at com.nxyl.food.manage.dao.hibernate.ProductDaoHB.getProduct(ProductDaoHB.java:46)

at com.nxyl.food.manage.service.imp.ProductServiceImp.getProduct(ProductServiceImp.java:33)

at com.nxyl.system.file.Test.main(Test.java:20)

** END NESTED EXCEPTION **

循环到4000左右出错,但在一台操作系统为windows2000系统下正常,其他的环境一样,请问是什么原因大家帮忙分析下

jongh
2008-06-29 15:07
是不是有些资源没有关掉

chenhuade85
2009-01-12 13:33
是你的服务器的端口给别的程序或类似的程序给霸占了

猜你喜欢