This is an example of how to create a UDBDataSource and get it bound with JNDI.
// Import the required packages. At deployment time,
// the JDBC driver-specific class that implements
// DataSource must be imported.
import java.sql.*;
import javax.naming.*;
import com.ibm.db2.jdbc.app.UDBDataSource;
public class UDBDataSourceBind
{
public static void main(java.lang.String[] args)
throws Exception
{
// Create a new UDBDataSource object and give it
// a description.
UDBDataSource ds = new UDBDataSource();
ds.setDescription("A simple UDBDataSource");
// Retrieve a JNDI context. The context serves
// as the root for where objects are bound or
// found in JNDI.
Context ctx = new InitialContext();
// Bind the newly created UDBDataSource object
// to the JNDI directory service, giving it a name
// that can be used to look up this object again
// at a later time.
ctx.rebind("SimpleDS", ds);
}
}