User ID-only security under the IBM Data Server Driver for JDBC and SQLJ
With the IBM® Data Server Driver for JDBC and SQLJ, one of the available security methods is user-ID only security.
To specify user ID security for a JDBC connection, use one of the following techniques.
For the DriverManager interface: Set
the user ID and security mechanism by setting the
user
and securityMechanism
properties
in a Properties object, and then invoking the form
of the getConnection method that includes the Properties object
as a parameter. 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 Properties();
// Create a Properties object
properties.put("user", "db2adm"); // Set user ID for the connection
properties.put("securityMechanism",
new String("" + com.ibm.db2.jcc.DB2BaseDataSource.USER_ONLY_SECURITY + ""));
// Set security mechanism to
// user ID only
String url = "jdbc:db2://mvs1.sj.ibm.com:5021/san_jose";
// Set URL for the data source
Connection con = DriverManager.getConnection(url, properties);
// Create the connection
For the DataSource interface: If
you create and deploy the DataSource object, you
can set the user ID and security mechanism by invoking the DataSource.setUser and DataSource.setSecurityMechanism methods
after you create the DataSource object. For example:
import java.sql.*; // JDBC base
import com.ibm.db2.jcc.*; // IBM Data Server Driver
// for JDBC and SQLJ
// implementation of JDBC
…
com.ibm.db2.jcc.DB2SimpleDataSource db2ds =
new com.ibm.db2.jcc.DB2SimpleDataSource();
// Create DB2SimpleDataSource object
db2ds.setDriverType(4); // Set the driver type
db2ds.setDatabaseName("san_jose"); // Set the location
db2ds.setServerName("mvs1.sj.ibm.com");
// Set the server name
db2ds.setPortNumber(5021); // Set the port number
db2ds.setUser("db2adm"); // Set the user ID
db2ds.setSecurityMechanism(
com.ibm.db2.jcc.DB2BaseDataSource.USER_ONLY_SECURITY);
// Set security mechanism to
// user ID only