title: how to know client ip port from jdbc connection
body: <p>I am testing about MSSQL. "how to long session information created after after connection?"</p>
  
  <p>So, try to connection with MSSQL JDBC, then select the sys.dm_exec_session and sys.dm_exec_connection with client Ip and port.</p>
  
  <p>But, I don't have any idea, how to get Client Ip and port from JDBC connection.</p>
  
  <p>or is it possible create JDBC connection using socket?</p>
  
  <p>show my test code.</p>
  
  <pre><code>try {
          DriverManager.registerDriver(
                  new com.microsoft.sqlserver.jdbc.SQLServerDriver());
          DriverManager.setLoginTimeout(10);
      } catch (Exception ex) {
          System.out.println("Fail to register sqlserver driver.");
          return;
      }
  
      String url = "jdbc:sqlserver://";
      String ip = "10.1.1.1";
      String port = "1433";
      String catalog = "master";
      String user = "jtlee";
      String pwd = "123456789";
  
      url = url + ip + ":" + port + ";databasename=" + catalog;
  
      Connection conn = null;
      PreparedStatement pstmt = null;
      ResultSet rs = null;
  
      try {
          long startTime = System.nanoTime();
  
          conn = DriverManager.getConnection(url, user, pwd);
          pstmt = conn.prepareStatement(
                  "SELECT "
                  + "     count(*) "
                  + "FROM "
                  + "     sys.dm_exec_connections connections,"
                  + "     sys.dm_exec_sessions sessions "
                  + "WHERE "
                  + "     connections.session_id = sessions.session_id "
                  + "     and connections.client_net_address= ? "
                  + "     and connections.client_tcp_port= ? ");
  
          /* I need this information... */
          String clientIp;
          int clientPort;
  
          pstmt.setString(1, clientIp);
          pstmt.setInt(2, clientPort);
          rs = pstmt.executeQuery();
  
          if (rs.next()) {
              ...
  </code></pre>
  
  <p>thanks for reading my strange English.</p>