DB2 Universal Driver examples

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.

jdbc:derby:net://localhost:1527/sample:user=judy;password=no12see;
retrieveMessagesFromServerOnGetMessage=true;

Example 2

The following example specifies both Derby and Universal Driver Attributes:
jdbc:derby:net://localhost:1527/sample;create=true:user=judy;
password=no12see;retrieveMessagesFromServerOnGetMessage=true;

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.

jdbc:derby:net://localhost:1527/"c:/my-db-dir/my-db-name":user=judy;
password=no12see;retrieveMessagesFromServerOnGetMessage=true;

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
Class.forName("com.ibm.db2.jcc.DB2Driver");
// 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);