IBM DB2 Manual page 28

Table of Contents

Advertisement

Example: Establishing a connection and setting the user ID and password in a URL:
String url = "jdbc:db2://myhost:5021/mydb:" +
Connection con = DriverManager.getConnection(url);
Example: Establishing a connection and setting the user ID and password in user and
password parameters:
String url = "jdbc:db2://myhost:5021/mydb";
String user = "dbadm";
String password = "dbadm";
Connection con = DriverManager.getConnection(url, user, password);
Example: Establishing a connection and setting the user ID and password in a
java.util.Properties object:
Properties properties = new Properties(); // Create Properties object
properties.put("user", "dbadm");
properties.put("password", "dbadm");
String url = "jdbc:db2://myhost:5021/mydb";
Connection con = DriverManager.getConnection(url, properties);
URL format for IBM Data Server Driver for JDBC and SQLJ type
4 connectivity
If you are using type 4 connectivity in your JDBC application, and you are making
a connection using the DriverManager interface, you need to specify a URL in the
DriverManager.getConnection call that indicates type 4 connectivity.
12
Application Programming Guide and Reference for Java
v Use the form of the getConnection method that specifies info, after setting the
user and password properties in a java.util.Properties object.
"user=dbadm;password=dbadm;";
Related concepts
"How to determine which type of IBM Data Server Driver for JDBC and SQLJ
connectivity to use" on page 17
"User ID and password security under the IBM Data Server Driver for JDBC
and SQLJ" on page 448
"User ID-only security under the IBM Data Server Driver for JDBC and SQLJ"
on page 450
"Encrypted password, user ID, or user ID and password security under the
IBM Data Server Driver for JDBC and SQLJ" on page 451
"Kerberos security under the IBM Data Server Driver for JDBC and SQLJ" on
page 453
"IBM Data Server Driver for JDBC and SQLJ trusted context support" on page
456
"IBM Data Server Driver for JDBC and SQLJ support for SSL" on page 458
Related tasks
"Connecting to a data source using the DriverManager interface with the IBM
Data Server Driver for JDBC and SQLJ" on page 11
Related reference
"Properties for the IBM Data Server Driver for JDBC and SQLJ" on page 201
// Set URL for data source
// Create connection
// Set URL for data source
// Create connection
// Set user ID for connection
// Set password for connection
// Set URL for data source
// Create connection

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents