-cp or -classpath Syntax on Different Systems

This section describes syntax differences of the -cp or -classpath option at the Java command line to specify JDBC implementation driver JAR files.

When you compile and run your Java programs that uses the JDBC API, you may need to specify a JDBC implementation driver JAR file with the -cp or -classpath option in the command line. The syntax of the -cp option is slightly on Linux/macOS systems than Windows systems.

1. -cp option on Windows systems uses ";" as the path delimiter and "\" as the directory delimiter:

Syntax: -cp path;dir\dir\file;dir\dir\name;...
Example: -cp .;\local\lib\jdbc_driver_x.jar;some\other.jar

2. -cp option on Linux and macOS systems uses ":" as the path delimiter and "/" as the directory delimiter:

Syntax: -cp path:dir/dir/file;dir/dir/name;...
Example: -cp .:/local/lib/jdbc_driver_x.jar:some/other.jar

3. -cp option on Windows systems can use disk driver letters in file path:

Syntax: -cp path:C:\dir\dir\file;D:dir\dir\name;...
Example: -cp .:C:\local\lib\jdbc_driver_x.jar:D:some\other.jar

4. -cp option on Linux and macOS systems can use the home directory shorthand symbol "~" on the first path only. If use "~" in the middle, it will not be replaced with the home directory.

Syntax: -cp ~/path:dir/dir/file;dir/dir/name;...
Example: -cp ~/mylib/jdbc_driver_x.jar:some/other.jar
Bad example: some/other.jar:~/mylib/jdbc_driver_x.jar

Table of Contents

 About This Book

 JDBC (Java Database Connectivity) Introduction

JDK (Java SE) Installation

 Downloading and Installing JDK

 Adding JDK "bin" Directory to Path Setting

 Downloading and Installing JDK on Mac

 Downloading and Installing JDK on Linux

 Compile and Run Java Programs

-cp or -classpath Syntax on Different Systems

 JDK Documentation Installation

 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

 Using Connection Pool with JDBC

 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

 Archived Tutorials


 Full Version in PDF/EPUB