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: ojdbc6.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-7.4.1.jre12.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 Java DB - Derby

 Derby (Java DB) JDBC Driver

 Derby (Java DB) JDBC DataSource Objects

 Java DB (Derby) - DML Statements

 Java DB (Derby) - ResultSet Objects of Queries

 Java DB (Derby) - PreparedStatement

 MySQL Installation on Windows

 MySQL JDBC Driver (MySQL Connector/J)

 MySQL - PreparedStatement

 MySQL - Reference Implementation of JdbcRowSet

 MySQL - JBDC CallableStatement

 MySQL CLOB (Character Large Object) - TEXT

 MySQL BLOB (Binary Large Object) - BLOB

 Oracle Express Edition Installation on Windows

 Oracle JDBC Drivers

 Oracle - Reference Implementation of JdbcRowSet

 Oracle - PreparedStatement

 Oracle - JBDC CallableStatement

 Oracle CLOB (Character Large Object) - TEXT

 Oracle BLOB (Binary Large Object) - BLOB

 Microsoft SQL Server Express Edition

 Microsoft JDBC Driver for SQL Server

 Microsoft JDBC Driver - Query Statements and Result Sets

 Microsoft JDBC Driver - DatabaseMetaData Object

 Microsoft JDBC Driver - DDL Statements

 Microsoft JDBC Driver - DML Statements

 SQL Server - PreparedStatement

 SQL Server CLOB (Character Large Object) - TEXT

 SQL Server BLOB (Binary Large Object) - BLOB

 JDBC-ODBC Bridge Driver - sun.jdbc.odbc.JdbcOdbcDriver

 JDBC-ODBC Bridge Driver - Flat Text Files

 JDBC-ODBC Bridge Driver - MS Access

 JDBC-ODBC Bridge Driver - MS SQL Server

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