db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Db-derby Wiki] Update of "UsingDb2Driver" by KimHaase
Date Tue, 05 Aug 2008 14:48:58 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Db-derby Wiki" for change notification.

The following page has been changed by KimHaase:
http://wiki.apache.org/db-derby/UsingDb2Driver

New page:
= Accessing the Network Server by using the DB2 Driver for JDBC =

Note: IBM(R) no longer tests or supports the DB2(R) Driver for JDBC with Derby.

You can use the IBM DB2 Driver for JDBC instead of the Derby network client driver to connect
to the Network Server. Your application needs to load the driver and connection URL that is
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 that you use to access the Network Server is:

{{{
 com.ibm.db2.jcc.DB2Driver
}}}

You must have the following two JAR files present in your classpath in order to use the DB2
Driver for JDBC:

    * {{{db2jcc.jar}}}
    * {{{db2jcc_license_c.jar}}}

The syntax of the URL that is required to access the Network Server is:

{{{
jdbc:derby:net://<server>[:<port>]/
<databaseName>[;<Derby URL attribute>=<value> [;...]]
[:<Universal Driver attribute>=<value>; [...;]]
}}}

After you specify the database name and attributes, you can include attributes for the DB2
Driver for JDBC. You must include a semicolon after the last DB2 Driver for JDBC 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 IP address, for example, {{{158.58.62.225}}}.
    Note: Unless the Network Server was started with the {{{-h}}} option or the {{{derby.drda.host}}}
property set, this value must be {{{localhost}}}.

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

  databaseName:: The name of the database that you are connecting to. The database name can
be a maximum of 18 characters. You must use quotation marks (") 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^TM^ environment
when you start 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 that are supported
by Derby. See the ''Derby Developer's Guide'' for more information.

  Universal Driver Attribute=value:: Optional database connection URL attributes that are
supported by the DB2 Driver for JDBC.

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

    The following DB2 Driver for JDBC attributes are available to you when running the Network
Server:

    user:: User name (required by the DB2 Driver for JDBC).

    password:: User password (required by the DB2 Driver for JDBC).

    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 tracing 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.

== DB2 Driver for JDBC System information ==

The Derby Network Server is compatible with the DB2 Driver for JDBC release 2.4 and higher.

== DB2 Driver for JDBC examples ==

The examples show how to specify the server name, database, and the URL attributes. You must
specify the user name and password attributes when you use the IBM DB2 Driver for JDBC.

=== 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}}}.

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

=== Example 2 ===

The following example specifies the attributes for both Derby and the DB2 Driver for JDBC:

{{{
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 quotation marks, 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 DB2
Driver for JDBC:

{{{
String databaseURL = "jdbc:derby:net://localhost:1527/sample";
// Load DB2 Driver for JDBC class
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
// 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); 
}}}

Mime
View raw message