底层程序缓存了正在使用的JDBC connection, 我需要知道我这次使用的connection与上一次使用的是不是同一个?该怎么做,请高手指教!!

解决方案 »

  1.   

    YES,就是用==比较这两个connection是否指向相同的堆
      

  2.   


    获得一个对象的虚拟机地址
    System.out.println(System.identityHashCode(s1)) ;//虚拟机地址
    System.out.println(System.identityHashCode(s2)) ;// 
      

  3.   

    这很直接常用获得一个对象的虚拟机地址
    System.out.println(System.identityHashCode(s1)) ;//虚拟机地址
    System.out.println(System.identityHashCode(s2)) ;// 
    这个也可以用就是相对用的少一些
      

  4.   

    谢谢大家,不过我可能没说清楚:
    底层程序实现了connection pool, 我拿到的只是个Proxy. 直接“==”, 没有意义啊。
      

  5.   

    我想问的是,有什么方法可以拿到类似 connection (or session ) id 的办法?