v com.ibm.db2.jcc.DB2XADataSource, which supports connection pooling and
distributed transactions. The connection pooling is provided by WebSphere
Application Server or another application server. You can use this
implementation only with IBM Data Server Driver for JDBC and SQLJ type 4
connectivity.
When you create and deploy a DataSource object, you need to perform these tasks:
1. Create an instance of the appropriate DataSource implementation.
2. Set the properties of the DataSource object.
3. Register the object with the Java Naming and Directory Interface (JNDI)
naming service.
The following example shows how to perform these tasks.
Note Description
1 Creates an instance of the DB2SimpleDataSource class.
2 This statement and the next three statements set values for properties of this
DB2SimpleDataSource object.
3 Creates a context for use by JNDI.
4 Associates DBSimple2DataSource object dbds with the logical name jdbc/sampledb.
An application that uses this object can refer to it by the name jdbc/sampledb.
Related concepts
“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 DataSource interface” on page 15
import java.sql.*; // JDBC base
import javax.naming.*; // JNDI Naming Services
import javax.sql.*; // Additional methods for JDBC
import com.ibm.db2.jcc.*; // IBM Data Server Driver for
// JDBC and SQLJ
// implementation of JDBC
// standard extension APIs
DB2SimpleDataSource dbds = new com.ibm.db2.jcc.DB2SimpleDataSource(); 1
dbds.setDatabaseName("db2loc1"); 2
dbds.setDescription("Our Sample Database");
dbds.setUser("john");
dbds.setPassword("mypw");
...
Context ctx=new InitialContext(); 3
Ctx.bind("jdbc/sampledb",dbds); 4
Figure 6. Example of creating and deploying a DataSource object
20 Application Programming Guide and Reference for Java
™