JDBC Tutorials - Herong's Tutorial Examples - v3.12, by Dr. Herong Yang
DriverManager - Connection URL
This section provides information about connection URL used by DriverManager to create a database connection.
As we learned earlier, the traditional way to create a connection object is to use the DriverManager class with a connection URL in the following format:
<subprotocol> in the URL is used to identify the JDBC driver class which will create a connection object based on information provided in <subname>. For example, "odbc" in the connection URL "jdbc:odbc:HY_FLAT" identifies the JDBC-ODBC Bridge driver. "sqlserver" in "jdbc:sqlserver://localhost:1269" identifies the Microsoft JDBC Driver.
<subname> in the URL is used to provide additional information to help the JDBC driver to identify the database server. If the database server is on remote host on the Internet, <subname> should have the following format:
For example, "HY_FLAT" in the connection URL "jdbc:odbc:HY_FLAT" provides the data source name to help JDBC-ODBC Bridge driver to create a connection object. "//localhost:1269" in "jdbc:sqlserver://localhost:1269" provides the host name and the port number to help Microsoft JDBC Driver to create a connection object.
The DriverManager class offers 3 methods for you to create a connection object using the specified connection URL:
Connection con = DriverManager.getConnection(String url); Connection con = DriverManager.getConnection(String url, Properties info) Connection con = DriverManager.getConnection(String url, String user, String password)
Tutorials of using connection URLs are included in other chapters in this book.
Table of Contents