I'm following Oracle's sample code in "Diagnosability in JDBC" at : https://docs.oracle.com/cd/B28359_01/java.111/b31224/diagnose.htm
My code looks like this :
ClassLoader l = oracle.jdbc.OracleDriver.class.getClassLoader();
String loader = l.getClass().getName() + "@" + l.hashCode();
System.out.println("loader = "+loader);
javax.management.ObjectName name=new javax.management.ObjectName("com.oracle.jdbc:type=diagnosability,name="+loader);
javax.management.MBeanServer mbs=java.lang.management.ManagementFactory.getPlatformMBeanServer(); // get the MBean server
System.out.println("LoggingEnabled = "+mbs.getAttribute(name,"LoggingEnabled")); DB_Logger.java:33 // find out if logging is enabled or not
mbs.setAttribute(name,new javax.management.Attribute("LoggingEnabled",true)); // enable logging
mbs.setAttribute(name,new javax.management.Attribute("LoggingEnabled",false)); // disable logging
The out put looks like this : loader = org.apache.catalina.loader.WebappClassLoader@929887595
The error message looks like this :
javax.management.InstanceNotFoundException: com.oracle.jdbc:type=diagnosability,name=org.apache.catalina.loader.WebappClassLoader@929887595 at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1095) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:643) at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:678) at com.mes.tools.DB_Logger.(DB_Logger.java:33)
The output line is causing the error, so how can I get the name correctly ?