Establishing a Database Connection

After an application has loaded the appropriate driver, it can establish a connection to the database. To connect to an embedded Apache Derby database, use the following getConnection() method:

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

The getConnection URL takes the form jdbc:derby:[subprotocol:][databasename][;attributes].

  • subprotocol is rarely used in the connection URL. This option specifies where Apache Derby should look for a database. This can be in a directory, a class path, or in a .JAR file. The majority of the time, this option is used for read-only databases.

  • databasename specifies a database name, with or without a relative or absolute path.

  • attributes specifies ...

Get Apache Derby—Off to the Races: Includes Details of IBM® Cloudscape™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.