您正在会话上执行查询,而会话仍在为其他进程获取连接。在事件结束之前,会话将无法使用触发postConnect事件的连接,这意味着该会话上的任何查询都将被迫获得其他连接。
您需要在SessionEvent中使用访问器来获取连接并使用它直接执行JDBC语句。就像是
public void postConnect(SessionEvent evt) { Connection connection = ((Accessor)event.getResult()).getConnection() Statement statement = connection.createStatement(); statement.execute("begin DBMS_SESSION.SET_IDENTIFIER('MyApplicationName'); end;"); }


