Hi,

I am trying to create a db2 connection pool by setting up the Apache Tomcat with the following configuration:

1) apache-tomcat-8.0.5/conf/context.xml
<Context>
<Resourcelink global="jdbc/db2conn" name="jdbc/db2conn" type="javax.sql.DataSource"
</Context>

2) apache-tomcat-8.0.5/conf/server.xml
<Resource
auth="Container"
name="jdbc/db2conn"
type="com.ibm.db2.jcc.DB2ConnectionPoolDataSource"
factory="com.ibm.db2.jcc.DB2DataSourceFactory"
serverName="db2awse"
portNumber="50001"
databaseName="sample"
username="db2inst1"
password="password"
driverClassName="com.ibm.db2.jcc.DB2Driver"
driverType="4"
removeAbandoned="true"
removeAbandonedTimeOut="300"
logAbandoned="true"
maxActive="8"
maxIdle="4" />


The java code will be as follows : -

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.ConnectionPoolDataSource;
import javax.sql.DataSource;
import javax.sql.PooledConnection;

import com.ibm.db2.jcc.*;


public class db2pool {

DB2ConnectionPoolDataSource ds = new com.ibm.db2.jcc.DB2ConnectionPoolDataSource();

public static void main (String[] args){
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;

try {
connection = getConnection();
statement = connection.createStatement();
String s = "SELECT * FROM db2inst1.customer";
resultSet = statement.executeQuery(s);

while (resultSet.next()) {
printCustomer(resultSet);
}

}
catch (Exception e) {
e.printStackTrace();
}

finally {
if (resultSet != null) {
try{
resultSet.close();
} catch (SQLException e){
}
}

if (statement != null) {
try {
statement.close();
} catch (SQLException e){
}
}

if (connection != null){
try {
connection.close();
} catch (SQLException e) {
}
}

}
}

private static Connection getConnection() throws NamingException,SQLException {
// TODO Auto-generated method stub
InitialContext initCtx = createContext();
String jndiName = "db2conn";
ConnectionPoolDataSource dataSource = (ConnectionPoolDataSource) initCtx.lookup(jndiName);
PooledConnection pooledConnection = dataSource.getPooledConnection();
return pooledConnection.getConnection();


}

private static InitialContext createContext() throws NamingException{
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,"COM.ibm.d b2.jndi.DB2InitialContextFactory");
env.put(Context.PROVIDER_URL,"localhost:50001");

InitialContext context = new InitialContext(env);
return context;

}

private static void printCustomer(ResultSet resultSet) throws SQLException {
System.out.println(resultSet.getString("customer_i d"));
}


}



When I run the java code, it has giving an error that sunrasign.jar is missing.
I have downloaded jdk 1.4 and extract the sunrasign.rar and make use of eclipse build-path-> configure build path to add it as external jar file.

Now, when I rerun the java code in eclipse, it show the following message:
javax.naming.NameNotFoundException: [IBM][JDBC Driver] CLI0637E db2conn cannot be found.
at COM.ibm.db2.jndi.DB2Context.lookup(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at db2.testplatform.db2pool.getConnection(db2pool.jav a:72)
at db2.testplatform.db2pool.main(db2pool.java:29)

Is there any issue with the above setup, configuration or java code?

Thanks in advance.