ORA-12516, TNS: 侦听器找不到可用的处理程序
Posted
技术标签:
【中文标题】ORA-12516, TNS: 侦听器找不到可用的处理程序【英文标题】:ORA-12516, TNS:listener could not find available handler 【发布时间】:2014-01-11 15:04:17 【问题描述】:我的错误:
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12516, TNS:listener could not find available handler with matching protocol
stack
The Connection descriptor used by the client was:
//10.2.5.21:9001/XE
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:261)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:
414)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtensio
n.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSou
rce.java:297)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java
:221)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java
:165)
at utilityService.DB_util.setOracleConnectionActive(DB_util.java:99)
at utilityService.DB_util.getRecPreparedAuthentication(DB_util.java:124)
我常用的db连接类:
package utilityService;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.pool.OracleDataSource;
public class DB_util
String propValue = "";
ResultSet rec = null;
Statement stm = null;
PreparedStatement pre_stm = null;
CallableStatement call_stm = null;
Connection conn1 = null;
/**
* Constructure to get oracle connection
*/
public DB_util()
Util util=new Util();
propValue=util.getFilePathToSave();
//propValue = Util.propValue;// get oracle connection
setOracleConnectionActive();
/**
* Close all oracle connections and result sets.
*/
public void setOracleConnectionClose()
try
if (conn1 != null || !conn1.isClosed())
if (rec != null)
rec.close();
rec = null;
if (stm != null)
stm.close();
stm = null;
if (pre_stm != null)
pre_stm.close();
pre_stm = null;
if (call_stm != null)
call_stm.close();
call_stm = null;
conn1.commit();
conn1.close();
conn1 = null;
catch (Exception ex)
ex.printStackTrace();
/**
* return a result set according to sql sent
*
* @param SQL
* @return
*/
public ResultSet getRec(String SQL)
try
setOracleConnectionActive();
stm = conn1.createStatement();
rec = stm.executeQuery(SQL);
return rec;
catch (Exception ex)
ex.printStackTrace();
return rec;
/**
* Activate oracle connection
*/
private void setOracleConnectionActive()
try
if (conn1 == null || conn1.isClosed())
OracleDataSource ods = new OracleDataSource();
if (propValue != null)
ods.setURL(propValue);
conn1 = ods.getConnection();
System.out.println("DB connection CONNECTED......");
conn1.setAutoCommit(false);
catch (Exception ex)
//setOracleConnectionActive();
ex.printStackTrace();
System.out.println("DB connection FAILED......");
/**
* send prepared result set with user authenticate
*
* @param SQL
* @param strInputUserMobile
* @param strInputUserName
* @param strInputUserPassword
* @return
*/
public ResultSet getRecPreparedAuthentication(String SQL,
String strInputUserMobile, String strInputUserName,
String strInputUserPassword)
try
setOracleConnectionActive();
pre_stm = conn1.prepareStatement(SQL);
pre_stm.setString(1, strInputUserMobile);
pre_stm.setString(2, strInputUserName);
pre_stm.setString(3, strInputUserPassword);
rec = pre_stm.executeQuery();
return rec;
catch (Exception ex)
ex.printStackTrace();
return rec;
/**
* insert sql to db which is send as a sql
*
* @param SQL
* @return
*/
public int insertSQL(String SQL)
int output = 0;
try
setOracleConnectionActive();
stm = conn1.createStatement();
output = stm.executeUpdate(SQL);
conn1.commit();
output = 1;
catch (Exception ex)
try
conn1.rollback();
output = 0;
catch (SQLException e)
e.printStackTrace();
output = 0;
ex.printStackTrace();
return output;
/**
* Send a callable statement according to sent sql
*
* @param SQL
* @return
*/
public CallableStatement callableStatementSQL(String SQL)
int output = 0;
try
setOracleConnectionActive();
call_stm = conn1.prepareCall(SQL);
catch (Exception ex)
try
conn1.rollback();
output = 0;
catch (SQLException e)
e.printStackTrace();
output = 0;
ex.printStackTrace();
return call_stm;
我引用这个类并执行我的获取和 CRUD 操作的每笔交易。 我的代码有问题吗?
【问题讨论】:
util.getFilePathToSave()
为您提供了什么 - 听起来像是文件路径而不是 JDBC URL,但是您不会从侦听器那里收到错误消息。您是立即收到此错误,还是在执行某些操作后收到此错误 - 也许您没有关闭连接并且侦听器/数据库的进程不足?
感谢亲爱的 Alex.its 提供 jdbc url。我会检查我的连接是否打开和关闭
【参考方案1】:
您打开了很多连接,这就是问题所在。我认为在您的代码中,您没有关闭打开的连接。
数据库弹跳可以暂时解决,但在您连续执行时会重新出现。 此外,还应验证与数据库的并发连接数。如果已达到最大 DB 进程参数,这是一个常见的症状。
感谢本帖:https://community.oracle.com/thread/362226?tstart=-1
【讨论】:
仅供参考,您可以使用hikari-cp 等连接池库限制最大连接数。基本公式是(number_of_cores * 2 + 1)
。 * 2
利用对磁盘的读/写阻塞特性。【参考方案2】:
我用 sql 命令行解决了这个问题:
connect system/<password>
alter system set processes=300 scope=spfile;
alter system set sessions=300 scope=spfile;
重启数据库。
【讨论】:
我这样做了,但也检查了我的应用程序的行为。在我的例子中,连接池被用于通过 dblink 使用对象。如果未执行显式提交/会话关闭,则该过程保持不变并达到限制。在池中保留 minimumIdle=0 解决了真正的问题。 愿幸运女神保佑你"Restart database"
。以上是关于ORA-12516, TNS: 侦听器找不到可用的处理程序的主要内容,如果未能解决你的问题,请参考以下文章
ORA-12516: TNS: 监听程序找不到符合协议堆栈要求的可用处理程”的异常
ORA-12516 TNS监听程序找不到符合协议堆栈要求的可用处理程序
ORA-12516 TNS: 监听程序找不到符合协议堆栈要求的可用处理程序
ORA-12516 "TNS监听程序找不到符合协议堆栈要求的可用处理程序" 解决方案
ORA-12516 "TNS监听程序找不到符合协议堆栈要求的可用处理程序" 解决方案
ORA-12516: TNS:listener could not find available handler with matching protocol stack