Java Database Connectivity (JDBC) - determine sql instance port number
843859Dec 28 2009 — edited Jan 8 2010To connect to a named instance through the Microsoft SQL Server Driver for JDBC, you must specify the port number that is associated with the named instance
e.g.: "jdbc:sqlserver://localhost:5002;DatabaseName=TestDB"
My problem is that my sql database(actually most of them) uses dynamic port numbers. If I restart the my database then sql server instance might use diffrent port.
So it is not possible to give hard coded value for port.
e.g "jdbc:sqlserver://localhost:5002;DatabaseName=TestDB"
because if the port changes, then it won't work. I would first need to determine the port number.
Is there any way to setup jdbc connection without specifying port number?