IBM DB2 Manual page 465

Table of Contents

Advertisement

import java.sql.*;
...
String url =
"jdbc:db2://mvs1.sj.ibm.com:5021/san_jose:user=dbadm;password=dbadm;";
Connection con = DriverManager.getConnection(url);
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.*;
import com.ibm.db2.jcc.*;
...
Properties properties = new java.util.Properties();
properties.put("user", "dbadm");
properties.put("password", "dbadm");
properties.put("securityMechanism",
new String("" + com.ibm.db2.jcc.DB2BaseDataSource.CLEAR_TEXT_PASSWORD_SECURITY +
""));
String url = "jdbc:db2://mvs1.sj.ibm.com:5021/san_jose";
Connection con = DriverManager.getConnection(url, properties);
For the DataSource interface: you can specify the user ID and password directly in
the DataSource.getConnection invocation. For example:
import java.sql.*;
import com.ibm.db2.jcc.*;
...
Context ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("jdbc/sampledb");
String id = "dbadm";
String pw = "dbadm";
Connection con = ds.getConnection(id, pw);
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 =
new com.ibm.db2.jcc.DB2SimpleDataSource();
ds.setDriverType(4);
ds.setDatabaseName("san_jose");
ds.setServerName("mvs1.sj.ibm.com");
ds.setPortNumber(5021);
ds.setUser("dbadm");
ds.setPassword("dbadm");
ds.setSecurityMechanism(
Chapter 10. Security under the IBM Data Server Driver for JDBC and SQLJ
// JDBC base
// Set URL for the data source
// Create connection
// JDBC base
// IBM Data Server Driver for JDBC
// and SQLJ implementation of JDBC
// Create Properties object
// Set user ID for the connection
// Set password for the connection
// Set security mechanism to
// user ID and password
// Set URL for the data source
// Create connection
// JDBC base
// IBM Data Server Driver for JDBC
// and SQLJ implementation of JDBC
// Create context for JNDI
// Get DataSource object
// Set user ID
// Set password
// Create connection
// Create DB2SimpleDataSource object
// Set driver type
// Set location
// Set server name
// Set port number
// Set user ID
// Set password
449

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents