-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

 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

 Using Connection Pool with JDBC

 Archived Tutorials

 References

 Full Version in PDF/EPUB