IBM DB2 Manual page 470

Table of Contents

Advertisement

...
Properties properties = new Properties(); // Create a Properties object
properties.put("user", "db2adm");
properties.put("password", "db2adm");
properties.put("kerberosServerPrincipal",
properties.put("securityMechanism",
String url = "jdbc:db2://mvs1.sj.ibm.com:5021/san_jose";
Connection con = DriverManager.getConnection(url, properties);
For the DataSource interface: If you create and deploy the DataSource object, set
the Kerberos server and security mechanism by invoking the
DataSource.setKerberosServerPrincipal and DataSource.setSecurityMechanism
methods after you create the DataSource object. For example:
import java.sql.*;
import com.ibm.db2.jcc.*;
...
com.ibm.db2.jcc.DB2SimpleDataSource db2ds =
db2ds.setDriverType(4);
db2ds.setDatabaseName("san_jose");
db2ds.setUser("db2adm");
db2ds.setPassword("db2adm");
db2ds.setServerName("mvs1.sj.ibm.com");
db2ds.setPortNumber(5021);
db2ds.setKerberosServerPrincipal(
db2ds.setSecurityMechanism(
Kerberos security with no user ID or password
For this case, the Kerberos default credentials cache must contain a ticket-granting
ticket (TGT) that lets you authenticate to the database server.
You need to set the kerberosServerPrincipal and securityMechanism properties.
Set the securityMechanism property to
com.ibm.db2.jcc.DB2BaseDataSource.KERBEROS_SECURITY (11).
For the DriverManager interface: Set the Kerberos server and security mechanism
by setting the kerberosServerPrincipal 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, use code like this to
set the Kerberos security mechanism without a user ID and password:
import java.sql.*;
import com.ibm.db2.jcc.*;
...
Properties properties = new Properties(); // Create a Properties object
454
Application Programming Guide and Reference for Java
"sample/srvlsj.ibm.com@SRVLSJ.SJ.IBM.COM");
new String("" +
com.ibm.db2.jcc.DB2BaseDataSource.KERBEROS_SECURITY + ""));
new com.ibm.db2.jcc.DB2SimpleDataSource();
"sample/srvlsj.ibm.com@SRVLSJ.SJ.IBM.COM");
com.ibm.db2.jcc.DB2BaseDataSource.KERBEROS_SECURITY);
// Set user ID for the connection
// Set password for the connection
// Set the Kerberos server
// Set security mechanism to
// Kerberos
// Set URL for the data source
// Create the connection
// JDBC base
// IBM Data Server Driver for JDBC
// and SQLJ implementation of JDBC
// Create the DataSource object
// Set the driver type
// Set the location
// Set the user
// Set the password
// Set the server name
// Set the port number
// Set the Kerberos server
// Set security mechanism to
// Kerberos
// JDBC base
// IBM Data Server Driver for JDBC
// and SQLJ implementation of JDBC

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents