JDBC Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 2.11

Creating Connections to Java DB (Derby) Network Server

This section describes how to create connections to Java DB (Derby) Network Server.

After I have my Java DB (Derby) started in Network Server mode, I am ready to try to create a connect object to access an existing database on the server. Here is my sample program showing you how to create a connection to access the TestDB:

/**
 * DerbyConnection.java
 * Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
 */
import java.sql.*;
public class DerbyConnection {
  public static void main(String [] args) {
    Connection con = null;
    try {

// Connect with a url string
      con = DriverManager.getConnection(
        "jdbc:derby://localhost/TestDB");
      System.out.println("Derby connection ok.");
      con.close();

    } catch (Exception e) {
      System.err.println("Exception: "+e.getMessage());
    }
  }
}

The output confirms that the DriverManager class loaded the driver class and created a connection to the Java DB (Derby) server correctly:

C:\>javac DerbyConnection.java

C:\>java -cp .;\local\javadb\lib\derbyclient.jar DerbyConnection
Derby connection ok.

Sections in This Chapter

Derby (Java DB) Driver Features

Loading Derby JDBC Driver Classes

Creating Connections to Java DB (Derby) Network Server

Java DB (Derby) Network Server and JDBC Driver Info

Java DB (Derby) - Creating New Tables

Java DB (Derby) - Inserting Data Rows to Existing Tables

Java DB (Derby) - Running SELECT Queries

Dr. Herong Yang, updated in 2007
Creating Connections to Java DB (Derby) Network Server