环境:MyEclipse 6.5+Tomcat6.0.18+Struts2.1+Hibernate3.2+Spring2.5.6
问题:启动Tomcat出现” java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Errorestablishing socket”异常。
出错信息如下:
2012-05-12 16:21:09,659 WARN[org.hibernate.cfg.SettingsFactory] - Could not obtain connection metadata
org.apache.commons.dbcp.SQLNestedException:Cannot create PoolableConnectionFactory ([Microsoft][SQLServer 2000 Driver forJDBC]Error establishing socket.)
atorg.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
atorg.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
atorg.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:82)
atorg.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
atorg.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
atorg.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
atorg.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
atorg.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
atorg.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1367)
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1333)
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:471)
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
atjava.security.AccessController.doPrivileged(Native Method)
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
atorg.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
atorg.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
atorg.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
atorg.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
atorg.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
atorg.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
atorg.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
atorg.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
atorg.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
atorg.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
atorg.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
atorg.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
atorg.apache.catalina.core.StandardHost.start(StandardHost.java:719)
atorg.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
atorg.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
atorg.apache.catalina.core.StandardService.start(StandardService.java:516)
atorg.apache.catalina.core.StandardServer.start(StandardServer.java:710)
atorg.apache.catalina.startup.Catalina.start(Catalina.java:578)
atsun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
atjava.lang.reflect.Method.invoke(Method.java:597)
atorg.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
atorg.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.sql.SQLException:[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
atcom.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
atcom.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
atcom.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
atcom.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
atcom.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
atcom.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
atcom.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
atcom.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
atorg.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
atorg.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
atorg.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
atorg.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
...49 more
2012-05-12 16:21:09,798 INFO[org.hibernate.dialect.Dialect] - Using dialect: org.hibernate.dialect.SQLServerDialect
2012-05-12 16:21:09,810 INFO[org.hibernate.transaction.TransactionFactoryFactory] - Transaction strategy:org.springframework.orm.hibernate3.SpringTransactionFactory
2012-05-12 16:21:09,853 INFO[org.hibernate.transaction.TransactionManagerLookupFactory] - NoTransactionManagerLookup configured (in JTA environment, use of read-write ortransactional second-level cache is not recommended)
2012-05-12 16:21:09,854 INFO[org.hibernate.cfg.SettingsFactory] - Automatic flush duringbeforeCompletion(): disabled
2012-05-12 16:21:09,854 INFO[org.hibernate.cfg.SettingsFactory] - Automatic session close at end oftransaction: disabled
2012-05-12 16:21:09,895 INFO[org.hibernate.cfg.SettingsFactory] - Scrollable result sets: disabled
2012-05-12 16:21:09,896 INFO[org.hibernate.cfg.SettingsFactory] - JDBC3 getGeneratedKeys(): disabled
2012-05-12 16:21:09,896 INFO[org.hibernate.cfg.SettingsFactory] - Connection release mode:after_transaction
2012-05-12 16:21:09,899 INFO [org.hibernate.cfg.SettingsFactory]- Default batch fetch size: 1
2012-05-12 16:21:09,899 INFO[org.hibernate.cfg.SettingsFactory] - Generate SQL with comments: disabled
2012-05-12 16:21:09,899 INFO[org.hibernate.cfg.SettingsFactory] - Order SQL updates by primary key: enabled
2012-05-12 16:21:09,899 INFO[org.hibernate.cfg.SettingsFactory] - Order SQL inserts for batching: disabled
2012-05-12 16:21:09,899 INFO[org.hibernate.cfg.SettingsFactory] - Query translator:org.hibernate.hql.ast.ASTQueryTranslatorFactory
2012-05-12 16:21:09,958 INFO[org.hibernate.hql.ast.ASTQueryTranslatorFactory] - UsingASTQueryTranslatorFactory
2012-05-12 16:21:09,959 INFO[org.hibernate.cfg.SettingsFactory] - Query language substitutions: {}
2012-05-12 16:21:09,959 INFO[org.hibernate.cfg.SettingsFactory] - JPA-QL strict compliance: disabled
2012-05-12 16:21:09,959 INFO[org.hibernate.cfg.SettingsFactory] - Second-level cache: enabled
2012-05-12 16:21:09,959 INFO[org.hibernate.cfg.SettingsFactory] - Query cache: disabled
2012-05-12 16:21:09,959 INFO[org.hibernate.cfg.SettingsFactory] - Cache provider:org.hibernate.cache.NoCacheProvider
2012-05-12 16:21:09,959 INFO[org.hibernate.cfg.SettingsFactory] - Optimize cache for minimal puts: disabled
2012-05-12 16:21:09,959 INFO[org.hibernate.cfg.SettingsFactory] - Structured second-level cache entries:disabled
2012-05-12 16:21:09,984 INFO[org.hibernate.cfg.SettingsFactory] - Echoing all SQL to stdout
2012-05-12 16:21:09,984 INFO[org.hibernate.cfg.SettingsFactory] - Statistics: disabled
2012-05-12 16:21:09,984 INFO[org.hibernate.cfg.SettingsFactory] - Deleted entity synthetic identifierrollback: disabled
2012-05-12 16:21:09,984 INFO[org.hibernate.cfg.SettingsFactory] - Default entity-mode: pojo
2012-05-12 16:21:09,985 INFO[org.hibernate.cfg.SettingsFactory] - Named query checking : enabled
2012-05-12 16:21:10,210 INFO[org.hibernate.impl.SessionFactoryImpl] - building session factory
2012-05-12 16:21:12,082 INFO[org.hibernate.impl.SessionFactoryObjectFactory] - Not binding factory to JNDI,no JNDI name configured
2012-05-12 16:21:12,166 INFO[org.springframework.orm.hibernate3.HibernateTransactionManager] - UsingDataSource [org.apache.commons.dbcp.BasicDataSource@6e795b] of HibernateSessionFactory for HibernateTransactionManager
2012-05-12 16:21:12,665 INFO[org.springframework.web.context.ContextLoader] - Root WebApplicationContext:initialization completed in 10242 ms
2012-05-12 16:21:13,008 INFO[com.opensymphony.xwork2.config.providers.XmlConfigurationProvider] - Parsingconfiguration file [struts-default.xml]
2012-05-12 16:21:13,398 INFO[com.opensymphony.xwork2.config.providers.XmlConfigurationProvider] - Parsingconfiguration file [struts-plugin.xml]
2012-05-12 16:21:13,458 INFO [com.opensymphony.xwork2.config.providers.XmlConfigurationProvider]- Parsing configuration file [struts.xml]
2012-05-12 16:21:13,482 INFO[org.apache.struts2.config.BeanSelectionProvider] - Loading global messagesfrom message
2012-05-12 16:21:13,881 INFO [org.apache.struts2.spring.StrutsSpringObjectFactory]- Initializing Struts-Spring integration...
2012-05-12 16:21:13,882 INFO[com.opensymphony.xwork2.spring.SpringObjectFactory] - Setting autowirestrategy to name
2012-05-12 16:21:13,882 INFO[org.apache.struts2.spring.StrutsSpringObjectFactory] - ... initializedStruts-Spring integration successfully
2012-05-12 16:21:15,144 INFO[org.directwebremoting.util.Logger] - Logging using commons-logging.
2012-05-12 16:21:15,153 INFO[org.directwebremoting.servlet.DwrServlet] - DWR Version 2.0.M2 starting.
2012-05-12 16:21:15,424 INFO[org.directwebremoting.convert.HibernateBeanConverter] - Found Hibernate3class: org.hibernate.Hibernate
2012-05-12 16:21:15,429 INFO[org.directwebremoting.dwrp.DefaultConverterManager] - Type 'org.jdom.Document'is not convertable due to missing converter 'jdom'. This is only an problem ifyou wanted to use it.
2012-05-12 16:21:15,429 INFO[org.directwebremoting.dwrp.DefaultConverterManager] - Type 'org.jdom.Element'is not convertable due to missing converter 'jdom'. This is only an problem ifyou wanted to use it.
2012-5-12 16:21:15org.apache.coyote.http11.Http11AprProtocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2012-5-12 16:21:15org.apache.coyote.ajp.AjpAprProtocol start
信息: Starting Coyote AJP/1.3 on ajp-8009
2012-5-12 16:21:15org.apache.catalina.startup.Catalina start
信息: Server startup in 41474 ms
分析:
这个项目使用的数据库是MySQL,根本就不是Microsoft SQLServer,但是为什么还会出现这个错误呢?上网查了查,有些说是驱动问题,有些说是服务没开,有些说需要打补丁,但是我使用的数据库都不是SQLServer,这些办法都不是办法。自己想了想,于是想到如下的解决办法。
解决:
查看端口,发现MySQL的默认端口3306已经启动。
找到Tomcat的安装目录X:\Program files\Tomcat 6.0\webapps,看看以前部署在这里面的项目是否有使用SQLServer,如果有,把这些项目移除,一方面解决问题,另一方面提高Tomcat的启动速度。再到这个目录X:\Program files\Tomcat 6.0\work\Catalina\localhost里把相应项目的文件移除。
使用Microsoft SQLServer数据库出现这个问题的解决办法:
http://zhidao.baidu.com/question/255235189.html?fr=qrl&cid=93&index=4
http://zhidao.baidu.com/question/89719381
http://hi.baidu.com/sleinet/blog/item/c829bca1f183068a471064d8.html