Release 10.1A: OpenEdge Data Management:
SQL Development

> ## Connecting from a Java application using a URL

> A Java application must perform two steps to connect to an OpenEdge database through a JDBC driver:

> 1. It must load the JDBC driver.

> 2. It must connect to the JDBC driver.

> To load the JDBC driver, call the `Class.forName` method in the JDBC application. The `Class.forName` method takes the fully qualified class name of the JDBC driver as its argument. The fully qualified class name for the JDBC driver is `com.ddtek.jdbc.openedge.OpenEdgeDriver`.

> This class name is case-sensitive and must be typed exactly as shown. The `Class.forName` method also registers the specified JDBC driver with the Driver Manager class so that the driver is available for connections.

> Here is an example of the call needed to load and register the driver:

>     CLASS.FORNAME ( "com.ddtek.jdbc.openedge.OpenEdgeDriver");

> Now that the JDBC driver has been loaded and registered, the `DriverManager.getConnection` method must be called to establish a connection to the database. The `getConnection` method takes three arguments:

> - A string containing a URL. The Driver Manager uses this URL to find a driver that can connect to the database represented by the given URL. Once the driver is found, the URL is used by the Driver class to establish the connection to the database.

> OpenEdge syntax for the URL string is:

>     jdbc:datadirect:openedge://host:port;databaseName=db_name;
>     servicename=service_name;
>     defaultSchema=schema_name;
>     statementCacheSize=Cachesize;

> See the "JDBC URL connection string" section for an explanation of each component.

> - The ID of the user trying to connect to the database.

> - The user’s password.

> ##### Database connection examples

> Several variations of the call needed to connect to the database follow:

> - Variation 1

>     Connection con = DriverManager.getConnection ( url, myuserid,
>                                                    mypassword );

> This is an example of how to connect to the OpenEdge database using Variation 1:

>     String url;
>     String myuserid;
>     String mypassword;
>     url = new String (
>     "jdbc:datadirect:openedge://myhost:6718;databaseName=sports2000" );
>     myuserid = new String ( "jones" );
>     mypassword = new String ( "secret" );
>     Connection con = DriverManager.getConnection ( url, myuserid,
>                                                    mypassword );

> - Variation 2

>     Connection con = DriverManager.getConnection ( url, info );

> In this variation `info` is a Properties object that contains a string of tag/value pairs used for connecting to the database. Normally the `info` object would include at least the user ID and password. The password is optional and defaults to `NULL`. However, once the `CREATE USER` statement has been executed and a user is created in the database, a password is required.

> The JDBC driver expects the user ID tag to be named `user` and the password tag to be named `password`. The user and password tags are case-sensitive and must be in all lowercase letters.

> This is an example of how to connect to the database using Variation 2 (tag/value pairs):

>     String url;
>     String myuserid;
>     String mypassword;
>     url = new String (
>     "jdbc:datadirect:openedge://myhost:6718;databaseName=sports2000" );
>     myuserid = new String ( " jones " );
>     mypassword = new String ( "secret " );
>     java.util.Properties info = new java.util.Properties ( );
>     info.put ( " user ", myuserid );
>     info.put ( " password ", mypassword );
>     Connection con = DriverManager.getConnection ( url, info );

> - Variation 3

>     Connection con = DriverManager.getConnection ( url );

> This variation takes only the URL as an argument. The URL in this case contains the `user` and `password` tags shown in Variation 2. The `password` is optional and defaults to `NULL`. However, once the `CREATE USER` statement has been executed and a user is created in the OpenEdge database, a password is required.

> The JDBC driver expects the user ID tag to be named user and the password tag to be named password. The `user` and `password` tags are case sensitive and must be in all lowercase letters.

> This is an example of how to connect to the OpenEdge database using Variation 3:

>     String url;
>     url = new String (
>     "jdbc:datadirect:openedge://myhost:6718;databaseName=sports2000;
>     user = jones ; password = secret" );
>     Connection con = DriverManager.getConnection ( url );

> - JDBC URL connection string

> The OpenEdge JDBC URL string has the following syntax:

>     jdbc:datadirect:openedge://host:port;databaseName=db_name;
>     servicename=service_name;
>     defaultSchema=schema_name;
>     statementCacheSize=CacheSize;

> This is an example of a connection string:

>     jdbc:datadirect:openedge://myhost:6718;databaseName=sports2000;

> This is an example of a connection string, using the optional `service_name` parameter:

>     jdbc:datadirect:openedge://myhost:-1;databaseName=sports2000;
>     servicename=myservice; defaultSchema=schema_name;
>     statementCacheSize=CacheSize;

> The components of the URL string are:

> - `jdbc:datadirect:openedge://`

> `jdbc` is the protocol to be used. The protocol in a JDBC URL is always `jdbc`.

> `datadirect` is the subprotocol and it designates the name of the JDBC driver.

> `openedge` indicates that the driver is for OpenEdge.

> - `host`

> The name of the host on which the OpenEdge database resides. If this is not specified it defaults to `localhost` (`localhost` is valid only if the database is not remote). The `host` is `myhost` in the example.

> - `port`

> Port number or service name to be used for the connection. The `port` is `6718` in the first example.

> Note: If you specify the `service_name`, the port must be `-1,` as shown in the second example.

> - `db_name`

> The name of the database. The `db_name` is `sports2000` in the example.

> - `service_name`

> An optional parameter, indicating the name of the service. The `service_name` is `myservice` in the example. If you specify `service_name`, the `port` must be `-1.`

> - `schema_name`

> Indicates the schema to be used during statement processing. For more information about the `defaultSchema` connection parameter, see the "JDBC connection parameters" section.

> - `CacheSize`

> Indicates how many entries will be in the statement cache. For more information about the `statementCacheSize` connection parameter, see the "JDBC connection parameters" section.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095