IBM DB2 Manual page 36

Table of Contents

Advertisement

v com.ibm.db2.jcc.DB2XADataSource, which supports connection pooling and
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)
The following example shows how to perform these tasks.
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import com.ibm.db2.jcc.*; // IBM Data Server Driver for
DB2SimpleDataSource dbds = new com.ibm.db2.jcc.DB2SimpleDataSource();
dbds.setDatabaseName("db2loc1");
dbds.setDescription("Our Sample Database");
dbds.setUser("john");
dbds.setPassword("mypw");
...
Context ctx=new InitialContext();
Ctx.bind("jdbc/sampledb",dbds);
Figure 6. Example of creating and deploying a DataSource object
Note
1
2
3
4
20
Application Programming Guide and Reference for Java
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.
naming service.
Description
Creates an instance of the DB2SimpleDataSource class.
This statement and the next three statements set values for properties of this
DB2SimpleDataSource object.
Creates a context for use by JNDI.
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
// JDBC base
// JNDI Naming Services
// Additional methods for JDBC
// JDBC and SQLJ
// implementation of JDBC
// standard extension APIs
1
2
3
4

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents