Passing the connection URL
- Last Updated: May 10, 2024
- 1 minute read
- DataDirect Connectors
- JDBC
- Documentation
After setting the CLASSPATH, the required connection information needs to be passed in the form of a connection URL. The following example includes the properties required for connecting with user ID/password authentication.
Connection URL Syntax
The connection URL takes the following form:
For Db2 for Linux, UNIX, and Windows; Db2 Hosted; and Db2 Warehouse on Cloud
jdbc:datadirect:db2://servername:port;
Database=databasename;User=userID;
Password=password;[property=value[;...]];
For Db2 for i and Db2 for z/OS
jdbc:datadirect:db2://servername:port;
LocationName=locationname;User=userID;
Password=password;[property=value[;...]];
where:
- servername
-
is either the IP address in IPv4 or IPv6 format, or the server name (if your network supports named servers) of the primary database server.
- port
-
is the number of the TCP/IP port.
- databasename
-
is the name of the database to which you want to connect.
- locationname
-
is the name of the DB2 location that you want to access.
- userID
-
specifies the user ID that is used to connect to the Db2 database.
- password
- specifies a password that is used to connect to your Db2 database.
- property=value
- specifies connection property settings. Multiple properties are separated by a semi-colon.
The following example connection string includes the properties required for connecting with the user ID/password authentication.
Connection conn = DriverManager.getConnection
("jdbc:datadirect:db2://myserver1:50000;
Database=account;User=jsmith;Password=secret;");
Connection conn = DriverManager.getConnection
("jdbc:datadirect:db2://myserver2:446;
LocationName=sample;User=jsmith;Password=secret;");