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

Connection URL Formats and Examples

This section provides a summary of connection URL formats and examples used by different JDBC drivers with the DriverManager class.

JDBC is recommending that the DataSource interface should be used to create database connection objects. But most Java applications are still using the DriverManager.getConnection() method to create connection objects. In order to use the DriverManager.getConnection() method, you need to provide a connection URL string that is recognized by the JDBC driver.

Different JDBC drivers requires different connection URL formats. A quick summary of various connection URL formats is provided here as a comparison and a reference:

Driver Name: Apache Derby Network Client JDBC Driver
------------
Driver JAR File: derbyclient.jar
Connection URL Formats: 
  jdbc:derby://host/database
Connection URL Examples:
  jdbc:derby://localhost/TestDB

Driver Name: JDBC-ODBC Bridge
------------
Driver JAR File: None (included in Java SE 1.6)
Connection URL Formats:
  jdbc:odbc:DSN[;user=xxx][;password=xxx]
Connection URL Examples:
  jdbc:odbc:HY_FLAT
  jdbc:odbc:HY_ACCESS
  jdbc:odbc:SQL_SERVER;user=sa;password=HerongYang

Driver Name: MySQL Connctor/J 
------------
Driver JAR File: mysql-connector-java-5.0.7-bin.jar
Connection URL Formats:
  jdbc:mysql://[host][:port]/[database][?p1=v1]...
Connection URL Examples:
  jdbc:mysql://localhost:3306/HerongDB?user=Herong&password=Secret
  jdbc:mysql://:3306/HerongDB?user=Herong&password=TopSecret
  jdbc:mysql://localhost/HerongDB?user=Herong&password=TopSecret
  jdbc:mysql://localhost:3306/?user=Herong&password=TopSecret
  jdbc:mysql://localhost/?user=Herong&password=TopSecret
  jdbc:mysql://:3306/?user=Herong&password=TopSecret
  jdbc:mysql:///HerongDB?user=Herong&password=TopSecret
  jdbc:mysql:///?user=Herong&password=TopSecret

Driver Name: Oracle JDBC Thin client-side driver
------------
Driver JAR File: ojdbc14.jar
Connection URL Formats:
  jdbc:oracle:thin:[user/password]@[host][:port]:SID
  jdbc:oracle:thin:[user/password]@//[host][:port]/SID
Connection URL Examples:
  jdbc:oracle:thin:Herong/TopSecret@localhost:1521:XE
  jdbc:oracle:thin:Herong/TopSecret@:1521:XE
  jdbc:oracle:thin:Herong/TopSecret@//localhost:1521/XE
  jdbc:oracle:thin:Herong/TopSecret@//:1521/XE
  jdbc:oracle:thin:Herong/TopSecret@//localhost/XE
  jdbc:oracle:thin:Herong/TopSecret@///XE

Driver Name: Miscrosoft JDBC Driver
------------
Driver JAR File: sqljdbc.jar
Connection URL Formats:
  jdbc:sqlserver://host[:port];user=xxx;password=xxx[;p=v]
Connection URL Examples:
  jdbc:sqlserver://localhost;user=sa;password=Herong
  jdbc:sqlserver://localhost:1269;user=sa;password=Herong
  jdbc:sqlserver://localhost;user=sa;password=Herong;database=myDB

Sections in This Chapter

JDBC Drivers Tested with Java SE 1.6

Connection URL Formats and Examples

Implementations of the DataSource Interface

Performances on Inserting Rows

Dr. Herong Yang, updated in 2007
Connection URL Formats and Examples