# Database connection examples

The examples in this section use the syntax of the connection URL for use in an embedded environment.

This information also applies to the client connection URL in a client/server environment. For reference information about client connection URLs, see "java.sql.Connection" in the Java DB Reference Manual.

- jdbc:derby:db1

  Open a connection to the database db1. db1 is a directory located in the system directory.

- jdbc:derby:london/sales

  Open a connection to the database london/sales. london is a subdirectory of the system directory, and sales is a subdirectory of the directory london.

- jdbc:derby:/reference/phrases/french

  Open a connection to the database /reference/phrases/french.

  On a UNIX system, this would be the path of the directory. On a Windows system, the path would be C:\reference\phrases\french if the current drive were C. If a jar file storing databases were in the user's classpath, this could also be a path within the jar file.

- jdbc:derby:a:/demo/sample

  Open a connection to the database stored in the directory \demo\sample on drive A (usually the floppy drive) on a Windows system.

- jdbc:derby:c:/databases/salesdb jdbc:derby:salesdb

  These two connection URLs connect to the same database, salesdb, on a Windows platform if the system directory of the Derby system is C:\databases.

- jdbc:derby:support/bugsdb;create=true

  Create the database support/bugsdb in the system directory, automatically creating the intermediate directory support if it does not exist.

- jdbc:derby:sample;shutdown=true

  Shut down the sample database.

- jdbc:derby:/myDB

  Access myDB (which is directly in a directory in the classpath) as a read-only database.

- jdbc:derby:classpath:/myDB

  Access myDB (which is directly in a directory in the classpath) as a read-only database. The reason for using the subsubprotocol is that it might have the same path as a database in the directory structure.

- jdbc:derby:jar:(C:/dbs.jar)products/boiledfood

  Access the read-only database boiledfood in the products directory from the jar file C:/dbs.jar.

- jdbc:derby:directory:myDB

  Access myDB, which is in the system directory. The reason for using the `directory:` subsubprotocol is that it might happen to have the same path as a database in the classpath.

Parent topic: Connecting to databases
Related concepts
Creating, dropping, and backing up databases
Connecting to databases within the system
Connecting to databases outside the system directory
Conventions for specifying the database path
Special database access
Offering connection choices to the user
Related reference
Embedded Derby JDBC database connection URL