Network client driver examples

The following examples specify the user and password URL attributes. To enable user authentication, the property derby.connection.requireAuthentication must be set to true, otherwise, Derby does not require a user name and password. For a multi-user product, you would typically set it for the system in the file for your server, since it is in a trusted environment. Below is a sample file that conforms to these examples:

Example 1

The following example connects to the default server name localhost on the default port, 1527, and to the database sample.


Example 2

The following example specifies both Derby and Network Client 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.


Example 4

The following example shows how to use the network client driver to connect the network client to the Network Server:

String databaseURL = "jdbc:derby://localhost:1527/sample";
// Load Derby Network Client driver class
// Set user and password properties
Properties properties = new Properties();
properties.put("user", "judy");
properties.put("password", "no12see");
// Get a connection
Connection conn = DriverManager.getConnection(databaseURL, properties); 
Related concepts
Accessing the Network Server by using the DB2 Universal Driver
Related reference
Network client security
Network client tracing