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 Connector/J
------------
Driver JAR File: mysql-connector-java-8.0.27.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: ojdbc11.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: mssql-jdbc-9.4.1.jre16.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

Table of Contents

 About This Book

 JDBC (Java Database Connectivity) Introduction

 JDK (Java SE) Installation

 Installing and Running Derby (Java DB)

 Derby (Java DB) JDBC Driver

 Derby (Java DB) JDBC DataSource Objects

 Derby (Java DB) - DML Statements

 Derby (Java DB) - ResultSet Objects of Queries

 Derby (Java DB) - PreparedStatement

Summary of JDBC Drivers and Database Servers

 List of Tested JDBC Drivers

Connection URL Formats and Examples

 Implementations of the DataSource Interface

 Performances on Inserting Rows

 Using Connection Pool with JDBC

 Archived Tutorials

 References

 Full Version in PDF/EPUB