Java DB

Apache Derby

Derby Developer's Guide

Derby Getting Started
Derby Reference Manual
Derby Developer's Guide
Derby Performance Tuning
Derby Server and Admin Guide
Derby Tools and Utilities
Derby Developer's Guide
-After installing
-Upgrades
-JDBC applications and Derby basics
-Application development overview
-Derby embedded basics
-Derby JDBC driver
-Derby JDBC database connection URL
-Derby system
-A Derby database
-Connecting to databases
-Working with the database connection URL attributes
-Using in-memory databases
-Working with Derby properties
-Deploying Derby applications
-Deployment issues
-Creating Derby databases for read-only use
-Loading classes from a database
-Derby server-side programming
-Programming database-side JDBC routines
-Programming trigger actions
-Programming Derby-style table functions
-Programming user-defined types
-Controlling Derby application behavior
-The JDBC connection and transaction model
-Result set and cursor mechanisms
-Locking, concurrency, and isolation
-Working with multiple connections to a single database
-Working with multiple threads sharing a single connection
-Working with database threads in an embedded environment
-Working with Derby SQLExceptions in an application
-Using Derby as a J2EE resource manager
-Derby and Security
-Configuring security for your environment
-Working with user authentication
-Users and authorization identifiers
-User authorizations
-Encrypting databases on disk
-Signed jar files
-Notes on the Derby security features
-User authentication and authorization examples
-Running Derby under a security manager
-Developing tools and using Derby with an IDE
-SQL tips
-Localizing Derby
-Derby and standards

 

Derby JDBC database connection URL

A Java application using the JDBC API establishes a connection to a database by obtaining a Connection object.

The standard way to obtain a Connection object is to call the method DriverManager.getConnection, which takes a String containing a connection URL (uniform resource locator). A JDBC connection URL provides a way of identifying a database. It also allows you to perform a number of high-level tasks, such as creating a database or shutting down the system.

An application in an embedded environment uses a different connection URL from that used by applications using the Derby Network Server in a client/server environment. See the Derby Server and Administration Guide for more information on the Network Server.

However, all versions of the connection URL (which you can use for tasks besides connecting to a database) have common features:

  • you can specify the name of the database you want to connect to
  • you can specify a number of attributes and values that allow you to accomplish tasks. For more information about what you can specify with the Derby connection URL, see Database connection examples.

The connection URL syntax is as follows:

jdbc:derby:[subsubprotocol:][databaseName][;attribute=value]*

Subsubprotocol, which is not typically specified, determines how Derby looks for a database: in a directory, in memory, in a class path, or in a jar file. Subsubprotocol is one of the following:

  • directory: The default. Specify this explicitly only to distinguish a database that might be ambiguous with one on the class path.
  • memory: Databases exist only in main memory and are not written to disk. An in-memory database may be useful when there is no need to persist the database -- for example, in some testing situations.
  • classpath: Databases are treated as read-only databases, and all databaseNames must begin with at least a slash, because you specify them "relative" to the classpath directory. See Accessing databases from the classpath for details.
  • jar: Databases are treated as read-only databases. DatabaseNames might require a leading slash, because you specify them "relative" to the jar file. See Accessing databases from a jar or zip file for details.

    jar requires an additional element immediately before the database name:

    (pathToArchive)

    pathToArchive is the path to the jar or zip file that holds the database.

For detailed reference about connection URL attributes and values, see "Setting attributes for the database connection URL" in the Derby Reference Manual.

The following example shows the use of the connection URL:

Connection conn = DriverManager.getConnection("jdbc:derby:sample");
 

javadb@jdbcurl.com