apache > db
Apache DB Project
Font size:      

Accessing the Network Server using the DB2 Universal Driver

Accessing the Network Server using the DB2 Universal Driver

When connecting to the Network Server, your application needs to load a driver and connection URL specific to the Network Server. In addition, you specify a user name and password. If you have not set up authentication, you can use any value for the user name and password. The driver you need to access the network server is:


The URL needed to access the network server is:

<databaseName>[;<Derby URL attribute>=<value> [;...]]
[:<Universal Driver attribute>=<value>; [...;]]

The syntax for connection to the Network Server differs slightly from the syntax used to connect to Derby running in embedded mode. After the database name and attributes you can include attributes for the DB2 JDBC Driver. You must include a semicolon after the last Universal Driver attribute.

  • server

    The name of the machine where the server is running. It can be the name of the machine (for example, buffy) or the address, for example,

    Unless the Network Server was started with the -h option or the derby.drda.host property set, this value should be localhost.
  • port

    The port the server is listening to. The default is 1527.

  • database name

    The name of the database you are connecting to. The database name can be at most 18 characters long. You must use double quotes (") to include path information in the database name. Alternately, you can specify path information by setting the property derby.system.home in either the derby.properties file or in the Java environment when starting the Network Server. See the Derby Developer's Guide for more information about defining the system home.

  • derby URL attribute=value

    Optional database connection URL attributes supported by Derby. See the Derby Developer's Guide for more information.

  • Universal Driver Attribute=value

    Optional database connection URL attributes supported by the DB2 Universal JDBC Driver.

    The DB2 JDBC Universal Driver requires that you set the Universal Driver user and password attributes to non-null values.

    Here's a list of the DB2 Universal JDBC Driver attributes available to you when running the Network Server:

    • user

      User name (required by the Universal JDBC Driver).

    • password

      User password (required by the Universal JDBC Driver).

    • portNumber

      The TCP/IP port number where the Network Server listens for connection requests to this data source. The default is 1527.

    • retrieveMessagesFromServerOnGetMessage

      Displays error messages from the server.

    • readOnly

      Creates a read-only connection. The default is false.

    • logWriter

      A character output stream. All logging and tracing messages print to the logWriter property.

    • traceLevel

      Specifies the granularity of logging messages to the logWriter property.

    • traceFile

      Provides an explicit file location for the trace output.

    • securityMechanism

      Indicates what type of security mechanism is used.

    • deferPrepares

      Controls when prepared statements are physically prepared in the database server. The default value is true.


Example 1

The following example connects to the default server name localhost on the default port, 1527, and to the database sample. It specifies the URL attributes user, password, and retrieveMessagesFromServerOnGetMessage. You must set the Universal Driver Attributes user name and password.


Example 2

The following example specifies both Derby and Universal Driver Attributes:


Example 3

This example connects to the default server name localhost on the default port, 1527, and includes the path in the database name portion of the URL. The database name must be delimited by double quotes and you cannot specify Derby attributes on the URL.


Example 4

The following is a sample program fragment that connects to the Network Server using the Universal Driver:

String databaseURL = "jdbc:derby:net://localhost:1527/sample";
// Load IBM JDBC Universal Driver class
// Set user and password properties
Properties properties = new Properties();
properties.put("user", "APP");
properties.put("password", "APP");
properties.put("retreiveMessagesFromServerOnGetMessage", "true");
// Get a connection
Connection conn = DriverManager.getConnection(databaseURL, properties); 

Universal Driver System information

The Derby Network Server is compatible with the DB2 JDBC Universal Driver release 1.2 and higher.

Previous Page
Next Page
Table of Contents