Bonjour, j'ai l'exception ci-dessus d'une application Spring, j'essaie de me connecter à une base de données Oracle
en cluster, mais même si j'essaie de me connecter à une seule instance, j'ai la même exception.
La définition du haricot est la suivante:
<bean id="dataSource" class="org.Apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="Oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:Oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=host_ip1)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(Host=host_ip2)(PORT=1521)))(LOAD_BALANCE=ON)(FAILOVER=ON)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=db)))" />
<property name="username" value="username" />
<property name="password" value="password" />
<property name="initialSize" value="10" />
</bean>
La trace de pile complète est:
2012-02-13 13:18:45,084 1375 [main] INFO org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
2012-02-13 13:18:45,207 1498 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
2012-02-13 13:18:45,207 1498 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not establish the connection)
2012-02-13 13:18:45,209 1500 [main] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection metadata
org.Apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not establish the connection)
at org.Apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.Java:1549)
at org.Apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.Java:1388)
at org.Apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.Java:1044)
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.Java:81)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.Java:76)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.Java:1933)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.Java:1216)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.Java:860)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.Java:779)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.Java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.Java:1479)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1417)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.Java:322)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.Java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.Java:1325)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.Java:844)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.Java:786)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.Java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.Java:547)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.Java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.Java:282)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.Java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:900)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:455)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.Java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.Java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.Java:339)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.Java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.Java:133)
at javax.servlet.GenericServlet.init(GenericServlet.Java:212)
at org.Apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.Java:1173)
at org.Apache.catalina.core.StandardWrapper.load(StandardWrapper.Java:993)
at org.Apache.catalina.core.StandardContext.loadOnStartup(StandardContext.Java:4350)
at org.Apache.catalina.core.StandardContext.start(StandardContext.Java:4659)
at org.Apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.Java:791)
at org.Apache.catalina.core.ContainerBase.addChild(ContainerBase.Java:771)
at org.Apache.catalina.core.StandardHost.addChild(StandardHost.Java:546)
at org.Apache.catalina.startup.HostConfig.deployDirectory(HostConfig.Java:1041)
at org.Apache.catalina.startup.HostConfig.deployDirectories(HostConfig.Java:964)
at org.Apache.catalina.startup.HostConfig.deployApps(HostConfig.Java:502)
at org.Apache.catalina.startup.HostConfig.start(HostConfig.Java:1277)
at org.Apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.Java:321)
at org.Apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.Java:119)
at org.Apache.catalina.core.ContainerBase.start(ContainerBase.Java:1053)
at org.Apache.catalina.core.StandardHost.start(StandardHost.Java:785)
at org.Apache.catalina.core.ContainerBase.start(ContainerBase.Java:1045)
at org.Apache.catalina.core.StandardEngine.start(StandardEngine.Java:445)
at org.Apache.catalina.core.StandardService.start(StandardService.Java:519)
at org.Apache.catalina.core.StandardServer.start(StandardServer.Java:710)
at org.Apache.catalina.startup.Catalina.start(Catalina.Java:581)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:39)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:25)
at Java.lang.reflect.Method.invoke(Method.Java:597)
at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:289)
at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:414)
Caused by: Java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
at Oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.Java:112)
at Oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.Java:146)
at Oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.Java:255)
at Oracle.jdbc.driver.T4CConnection.logon(T4CConnection.Java:387)
at Oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.Java:441)
at Oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.Java:165)
at Oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.Java:35)
at Oracle.jdbc.driver.OracleDriver.connect(OracleDriver.Java:801)
at org.Apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.Java:38)
at org.Apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.Java:582)
at org.Apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.Java:1556)
at org.Apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.Java:1545)
... 75 more
Changer les adresses IP en leurs noms DNS, j'ai une exception différente, la trace de la pile est ci-dessous:
2012-02-13 13:46:36,709 1685 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
2012-02-13 13:46:36,709 1685 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Error preloading the connection pool
2012-02-13 13:46:36,710 1686 [main] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection metadata
org.Apache.commons.dbcp.SQLNestedException: Error preloading the connection pool
at org.Apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.Java:1398)
at org.Apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.Java:1044)
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.Java:81)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.Java:76)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.Java:1933)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.Java:1216)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.Java:860)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.Java:779)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.Java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.Java:1479)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1417)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.Java:322)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.Java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.Java:1325)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.Java:844)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.Java:786)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.Java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.Java:547)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.Java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.Java:282)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.Java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:900)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:455)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.Java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.Java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.Java:339)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.Java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.Java:133)
at javax.servlet.GenericServlet.init(GenericServlet.Java:212)
at org.Apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.Java:1173)
at org.Apache.catalina.core.StandardWrapper.load(StandardWrapper.Java:993)
at org.Apache.catalina.core.StandardContext.loadOnStartup(StandardContext.Java:4350)
at org.Apache.catalina.core.StandardContext.start(StandardContext.Java:4659)
at org.Apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.Java:791)
at org.Apache.catalina.core.ContainerBase.addChild(ContainerBase.Java:771)
at org.Apache.catalina.core.StandardHost.addChild(StandardHost.Java:546)
at org.Apache.catalina.startup.HostConfig.deployDirectory(HostConfig.Java:1041)
at org.Apache.catalina.startup.HostConfig.deployDirectories(HostConfig.Java:964)
at org.Apache.catalina.startup.HostConfig.deployApps(HostConfig.Java:502)
at org.Apache.catalina.startup.HostConfig.start(HostConfig.Java:1277)
at org.Apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.Java:321)
at org.Apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.Java:119)
at org.Apache.catalina.core.ContainerBase.start(ContainerBase.Java:1053)
at org.Apache.catalina.core.StandardHost.start(StandardHost.Java:785)
at org.Apache.catalina.core.ContainerBase.start(ContainerBase.Java:1045)
at org.Apache.catalina.core.StandardEngine.start(StandardEngine.Java:445)
at org.Apache.catalina.core.StandardService.start(StandardService.Java:519)
at org.Apache.catalina.core.StandardServer.start(StandardServer.Java:710)
at org.Apache.catalina.startup.Catalina.start(Catalina.Java:581)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:39)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:25)
at Java.lang.reflect.Method.invoke(Method.Java:597)
at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:289)
at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:414)
Caused by: Java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
at Oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.Java:112)
at Oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.Java:146)
at Oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.Java:255)
at Oracle.jdbc.driver.T4CConnection.logon(T4CConnection.Java:387)
at Oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.Java:441)
at Oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.Java:165)
at Oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.Java:35)
at Oracle.jdbc.driver.OracleDriver.connect(OracleDriver.Java:801)
at org.Apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.Java:38)
at org.Apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.Java:582)
at org.Apache.commons.pool.impl.GenericObjectPool.addObject(GenericObjectPool.Java:1059)
at org.Apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.Java:1395)
... 74 more
Je devais aller chercher ojdbc compatible avec la version sur Oracle qui était installé ce qui a résolu mon problème, mon mauvais pensait qu'un ojdbc fonctionnerait pour tous
Il suffit de vérifier les fichiers tnsnames.ora et listener.ora. Il ne devrait pas y avoir localhost en tant que serveur. changez-le en nom d'hôte.
Comme dans tnsnames.ora
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(Host = localhost)(PORT = 1521))
Remplacez localhost par nom d'hôte.
J'ai eu une erreur similaire avec Tomcat 8.0/MySQL. Changer la valeur de l'url jdbc de localhost à 127.0.0.1 a résolu le problème.
J'ai eu la même erreur et j'ai fini par la résoudre en mettant à niveau mon pilote Oracle ojdbc vers une version compatible avec la version de la base de données Oracle
J'étais également confronté à l'erreur "Erreur de préchargement du pool de connexions" lors de l'utilisation d'Oracle 10g Express Edition avec mon application Spring et CAS lors de la connexion.
Mon application basée sur CAS n'a que class12.jar dans son chemin de classe. Placer ojdbc14.jar dans le chemin de classe a résolu mon problème.
La plupart des cas sont dus à un problème de nom d’hôte. Vérifiez le nom d’hôte. Parfois, l’équipe de la base de données conservera plusieurs noms d’hôte pour connecter la même base de données. S'il vous plaît vérifier avec l'équipe de base de données concernant ce problème de connexion.