Skip to content

Instantly share code, notes, and snippets.

@muhdkhokhar
Created February 15, 2025 10:23
Show Gist options
  • Save muhdkhokhar/6efaa31f13dc6253ac730e87fd13af46 to your computer and use it in GitHub Desktop.
Save muhdkhokhar/6efaa31f13dc6253ac730e87fd13af46 to your computer and use it in GitHub Desktop.
private int getSessionId(Connection connection) throws Exception {
try (PreparedStatement ps = connection.prepareStatement("SELECT @@SPID");
ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
return rs.getInt(1);
}
}
throw new RuntimeException("Failed to retrieve session ID.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment