JDBC Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 2.11

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:

jdbc:<subprotocol>:<subname>

<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:

jdbc:<subprotocol>://<hostname>:port<subname>

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 sections in this book.

Sections in This Chapter

What Is JDBC?

JDBC Version and History

JDBC Driver Types

Establishing Connections from JDBC to Databases

DriverManager - Loading JDBC Driver

DriverManager - Connection URL

Dr. Herong Yang, updated in 2007
DriverManager - Connection URL