Spring连接池问题

我没有Java和Spring的经验。 我尝试编写一个使用JdbcTemplate进行数据访问的程序。 我使用DBCP池,这里是:

        

我的应用程序执行多个更新操作,然后抛出exception:

  7053 [SenderThread-0] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource Exception in thread "SenderThread-0" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Listener refused the connection with the following error: ORA-12519, TNS:no appropriate service handler found The Connection descriptor used by the client was: 192.168.2.7:1521:xe ) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:572) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:811) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:867) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:875) at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.update(SimpleJdbcTemplate.java:249) at com.talutek.manifesto.dao.firestorm.dao.spring.MessageItemsTableDaoImpl.update(MessageItemsTableDaoImpl.java:52) at com.talutek.manifesto.lib.MessageItemMngr.updateItem(MessageItemMngr.java:115) at com.talutek.manifesto.gw.SenderThread.run(SenderThread.java:42) at java.lang.Thread.run(Thread.java:619) Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Listener refused the connection with the following error: ORA-12519, TNS:no appropriate service handler found The Connection descriptor used by the client was: 192.168.2.7:1521:xe ) 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.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) ... 9 more Caused by: java.sql.SQLException: Listener refused the connection with the following error: ORA-12519, TNS:no appropriate service handler found The Connection descriptor used by the client was: 192.168.2.7:1521:xe at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70) at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:110) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:171) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:496) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:411) at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:490) at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:202) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:465) 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) ... 13 more 

当我更改池设置(池大小)时,应用程序可以运行多次,但随后崩溃。 我认为问题与汇集有关,但我无法解决。

有什么建议么?

当许multithreading同时访问数据库时,我发生了同样的错误,并且每个线程都有一个单独的DBCP BasicDataSource和一个单独的Spring JdbcTemplate

通过使BasicDataSourceJdbcTemplate成为所有线程共享的单例,我可以避免此错误。 这也是SpringSource推荐的。

谷歌搜索会有所帮助: http : //www.dba-oracle.com/sf_ora_12519_tns_no_appropriate_service_handler_found.htm

几点建议:尽可能使用应用服务器池使用c3p0而不是DBCP

使用oracle.jdbc.pool.OracleDataSource