Hi Alex,
Use the jdbc:sqlserver:// syntax with the instance name: SQL Server supports JDBC connections to a named instance without specifying the port directly.
Syntax:
jdbc:sqlserver://ServerName\\InstanceName;databaseName=YourDatabase;integratedSecurity=true;
You can refer this for your solution.
https://stackoverflow.com/questions/52893597/jdbc-connection-to-sql-server-with-dynamic-tcp-ports
Thanks,
Arun