import java.sql.*; // JDBC base
...
String url =
"jdbc:db2://mvs1.sj.ibm.com:5021/san_jose:user=dbadm;password=dbadm;";
// Set URL for the data source
Connection con = DriverManager.getConnection(url);
// Create connection
Alternatively, you can set the user ID and password by setting the user and
password properties in a Properties object, and then invoking the form of the
getConnection method that includes the Properties object as a parameter.
Optionally, you can set the securityMechanism property to indicate that you are
using user ID and password security. For example:
import java.sql.*; // JDBC base
import com.ibm.db2.jcc.*; // IBM Data Server Driver for JDBC
// and SQLJ implementation of JDBC
...
Properties properties = new java.util.Properties();
// Create Properties object
properties.put("user", "dbadm"); // Set user ID for the connection
properties.put("password", "dbadm"); // Set password for the connection
properties.put("securityMechanism",
new String("" + com.ibm.db2.jcc.DB2BaseDataSource.CLEAR_TEXT_PASSWORD_SECURITY +
""));
// Set security mechanism to
// user ID and password
String url = "jdbc:db2://mvs1.sj.ibm.com:5021/san_jose";
// Set URL for the data source
Connection con = DriverManager.getConnection(url, properties);
// Create connection
For the DataSource interface: you can specify the user ID and password directly in
the DataSource.getConnection invocation. For example:
import java.sql.*; // JDBC base
import com.ibm.db2.jcc.*; // IBM Data Server Driver for JDBC
// and SQLJ implementation of JDBC
...
Context ctx=new InitialContext(); // Create context for JNDI
DataSource ds=(DataSource)ctx.lookup("jdbc/sampledb");
// Get DataSource object
String id = "dbadm"; // Set user ID
String pw = "dbadm"; // Set password
Connection con = ds.getConnection(id, pw);
// Create connection
Alternatively, if you create and deploy the DataSource object, you can set the user
ID and password by invoking the DataSource.setUser and
DataSource.setPassword methods after you create the DataSource object.
Optionally, you can invoke the DataSource.setSecurityMechanism method property
to indicate that you are using user ID and password security. For example:
...
com.ibm.db2.jcc.DB2SimpleDataSource ds = // Create DB2SimpleDataSource object
new com.ibm.db2.jcc.DB2SimpleDataSource();
ds.setDriverType(4); // Set driver type
ds.setDatabaseName("san_jose"); // Set location
ds.setServerName("mvs1.sj.ibm.com"); // Set server name
ds.setPortNumber(5021); // Set port number
ds.setUser("dbadm"); // Set user ID
ds.setPassword("dbadm"); // Set password
ds.setSecurityMechanism(
Chapter 10. Security under the IBM Data Server Driver for JDBC and SQLJ 449