v Use the form of the getConnection method that specifies info, after setting the
user and password properties in a java.util.Properties object.
Example: Establishing a connection and setting the user ID and password in a URL:
String url = "jdbc:db2://myhost:5021/mydb:" +
"user=dbadm;password=dbadm;";
// Set URL for data source
Connection con = DriverManager.getConnection(url);
// Create connection
Example: Establishing a connection and setting the user ID and password in user and
password parameters:
String url = "jdbc:db2://myhost:5021/mydb";
// Set URL for data source
String user = "dbadm";
String password = "dbadm";
Connection con = DriverManager.getConnection(url, user, password);
// Create connection
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"); // Set user ID for connection
properties.put("password", "dbadm"); // Set password for connection
String url = "jdbc:db2://myhost:5021/mydb";
// Set URL for data source
Connection con = DriverManager.getConnection(url, properties);
// Create connection
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
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
™