jndi jdbc App Server Integration

We are seeing the following error in -

/jes/var/opt/SUNWappserver/domains/domain1/logs/server.log

[#|2007-07-26T10:58:47.790-0400|FINE|sun-appserver-ee8.1_02|

javax.enterprise.resource.resourceadapter|_ThreadID=27;|

RAR5036:Resource reference is not defined for JNDI name [jdbc/MarxDB]|#]

Application server is -

Sun Java System Application Server 8.1_02 (build b21-p10)

Excerpt from our test java class

System.out.println("\n.MARKER2 before dataSource.getConnection().\n");

Above seen in log files.

dbConnection = dataSource.getConnection();

System.out.println("\n.after dataSource.getConnection().\n");

Above never seen in log files.

Excerpt from our server.log.

.MARKER2 before dataSource.getConnection().

|#]

[#|2007-07-26T10:58:47.790-0400|FINE|sun-appserver-ee8.1_02|

javax.enterprise.resource.resourceadapter|_ThreadID=27;|

RAR5036:Resource reference is not defined for JNDI name [jdbc/MarxDB]|#]

Excerpt from /jes/var/opt/SUNWappserver/domains/domain1/config/domain.xml

<jdbc-resource enabled="true" jndi-name="jdbc/MarxDB" object-type="user" pool-name="MARXDB"/>

<jdbc-connection-pool connection-validation-method="auto-commit"

datasource-classname="COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource"

fail-all-connections="true"

idle-timeout-in-seconds="300"

is-connection-validation-required="true"

is-isolation-level-guaranteed="false"

max-pool-size="32"

max-wait-time-in-millis="8000"

name="MARXDB"

pool-resize-quantity="4"

res-type="javax.sql.ConnectionPoolDataSource"

steady-pool-size="8"

validation-table-name="mcs_user_status">

<property name="user" value="IACSTNV"/>

<property name="url" value="jdbc:db2:HCFADB1T"/>

<property name="password" value="CKM349AB"/>

<property name="databaseName" value="HCFADB1T"/>

<property name="portNumber" value="50000"/>

</jdbc-connection-pool>

[2068 byte] By [mciacciomenfia] at [2007-11-15]
# 1

1) What type of component do you use ? ( eg: EJB/Servlet ..)

2) Could you please provide the code snippet that does lookup of datasource.

3) Also, deployment descriptors that you use (eg: ejb-jar.xml, sun-ejb-jar.xml)

Jagadish.Prasatha at 2007-7-29 > top of java,Application & Integration Servers,Application Servers...
# 2

Here is the java

package gov.hhs.cms.ebs.das;

import gov.hhs.cms.ebs.log.LogManager;

import gov.hhs.cms.ebs.util.PropertiesUtil;

import java.sql.CallableStatement;

import java.sql.Connection;

import java.sql.SQLException;

import java.sql.Types;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.sql.DataSource;

import java.util.Hashtable;

import java.util.Enumeration;

public class MarxDas {

private static int MARX_COUNTER = 0;

private static Connection getConnection(String MARX_DB_DATASOURCE) {

System.out.println("\nMarxDas cl, getConnection md arg is ." + MARX_DB_DATASOURCE + ".\n");

LogManager.debug("Inside getConnection method of MarxDao");

Connection dbConnection = null;

InitialContext ic = null;

DataSource dataSource = null;

try {

LogManager.debug("getConnection: Trying to establish a DB2 connection");

ic = new InitialContext();

System.out.println("\nMarxDas cl, getConnection md ic.getNameInNamespace is ." + ic.getNameInNamespace() + ".\n");

Hashtable myHashtable = ic.getEnvironment();

System.out.println("\nMarxDas cl, getConnection md myHashtable isEmpty is ." + myHashtable.isEmpty() + ".\n");

Enumeration enum = myHashtable.keys();

while ( enum.hasMoreElements() ) {

Object myKey = enum.nextElement();

System.out.println("\nMarxDas cl, getConnection md Hashtable key is ." + myKey + ".\n");

System.out.println("\nMarxDas cl, getConnection md value is ." + myHashtable.get(myKey) + ".\n");

}

// System.out.println("\nMarxDas cl, ic.lookup(MARX_DB_DATASOURCE) is." + ic.lookup(MARX_DB_DATASOURCE) + ".\n");

if ( (DataSource) ic.lookup(MARX_DB_DATASOURCE) == null ) {

System.out.println("\n (DataSource) ic.lookup(MARX_DB_DATASOURCE) is NULL." );

}

else {

System.out.println("\n (DataSource) ic.lookup(MARX_DB_DATASOURCE) is NOT NULL.\n");

System.out.println("\n (DataSource) ic.lookup(MARX_DB_DATASOURCE) is ." + (DataSource) ic.lookup(MARX_DB_DATASOURCE) + ".\n");

}

if (ic != null) {

dataSource = (DataSource) ic.lookup(MARX_DB_DATASOURCE);

System.out.println("\ndataSource is ." + dataSource + ".\n");

if (dataSource != null) {

System.out.println("\n.before dataSource.getConnection().\n");

System.out.println("\n.MARKER2 before dataSource.getConnection().\n");

// dbConnection = ((com.sun.gjc.spi.DataSource)dataSource).getConnection();

dbConnection = dataSource.getConnection();

System.out.println("\n.after dataSource.getConnection().\n");

}

}

} catch (Exception e) {

LogManager.error(

"getConnection: Exception occurred while getting datasource: "

+ e.getMessage());

}

System.out.println("\nMarxDas cl, getConnection md dbConnection is ." + dbConnection + ".\n");

return dbConnection;

}

public static String checkMarxConnection(String MARX_DB_DATASOURCE) {

System.out.println("\nMarxDas cl, checkMarxConnection md arg is ." + MARX_DB_DATASOURCE + ".\n");

LogManager.debug("Inside checkMarxConnection method of MarxDao");

Connection dbConnection = null;

try {

dbConnection = getConnection(MARX_DB_DATASOURCE);

System.out.println("\n.9.\n");

/*if (dbConnection == null && MARX_COUNTER < 10) {

MARX_COUNTER = MARX_COUNTER+1;

LogManager.debug("MARX COUNTER is "+MARX_COUNTER);

String timeout = PropertiesUtil.getProperty("iacs", "MARX_POLL_WAIT");

Thread.sleep(new Long(timeout).longValue());

LogManager.debug("Returning FALSE");

return "false";

} else {

LogManager.debug("MARX COUNTER is "+MARX_COUNTER);

LogManager.debug("Resetting MARX COUNTER to 0 and returning TRUE");

MARX_COUNTER = 0;

return "true";

}*/

if (dbConnection == null) {

String timeout =

PropertiesUtil.getProperty("iacs", "MARX_POLL_WAIT");

LogManager.debug(

"checkMarxConnection: connection is null; about to enter a sleep");

Thread.sleep(new Long(timeout).longValue());

LogManager.debug("checkMarxConnection: returning FALSE");

return "false";

} else {

LogManager.debug(

"checkMarxConnection: connection is not null; returning TRUE");

return "true";

}

} catch (NumberFormatException e1) {

LogManager.error(

"Check MARX Connection: NumberFormatException occurred: "

+ e1.getMessage());

return "false";

} catch (InterruptedException e2) {

LogManager.error(

"Check MARX Connection: InterruptedException occurred: "

+ e2.getMessage());

return "false";

} finally {

try {

dbConnection.close();

} catch (SQLException e) {

e.printStackTrace();

}

}

}

public static String createMarxAccount(

String requesterUserId,

String userIdmId,

String userId,

//This is the RACF ID

String userFirstname,

String userLastname,

String userMiddleInitial,

int roleCount,

String roleData,

int ACSCount,

String ACSData,

int userOrgType,

String userOrgName,

String MARX_DB_DATASOURCE,

String MARX_DB_STORPROC_NAME) {

Connection dbConnection = getConnection(MARX_DB_DATASOURCE);

String replyStatus = "";

CallableStatement callableStatement = null;

String query =

"{call " + MARX_DB_STORPROC_NAME + " (?,?,?,?,?,?,?,?,?,?,?,?,?) }";

try {

LogManager.debug(" After getConnection");

callableStatement = dbConnection.prepareCall(query);

LogManager.debug("preparecall is a success");

callableStatement.setString(1, requesterUserId);

LogManager.debug("requesterUserId is a success");

callableStatement.setString(2, userIdmId);

LogManager.debug("IDMiD is a success");

callableStatement.setString(3, userId);

LogManager.debug("userId is a success");

callableStatement.setString(4, userFirstname);

LogManager.debug("userFirstname is a success");

callableStatement.setString(5, userLastname);

LogManager.debug("userLastname is a success");

callableStatement.setString(

6,

(userMiddleInitial == null) ? "" : userMiddleInitial);

LogManager.debug("userMiddleInitial is a success");

//callableStatement.setShort(7, Short.valueOf(roleCount).shortValue());

callableStatement.setShort(7, (short) roleCount);

LogManager.debug("roleCount is a success");

callableStatement.setString(8, roleData);

LogManager.debug("roleData is a success");

//callableStatement.setShort(9, Short.valueOf(ACSCount).shortValue());

callableStatement.setShort(9, (short) ACSCount);

LogManager.debug("ACSCount is a success");

callableStatement.setString(10, ACSData);

LogManager.debug("ACSData is a success");

callableStatement.setShort(11, (short) userOrgType);

LogManager.debug("userOrgType is a success");

if (userOrgName!=null && userOrgName.length()>20) {

userOrgName = userOrgName.substring(0, 20);

}

callableStatement.setString(12, userOrgName);

LogManager.debug("userOrgName is a success");

LogManager.debug(" input args all success");

callableStatement.registerOutParameter(13, Types.CHAR);

LogManager.debug(" After registerOutParameter");

callableStatement.execute();

LogManager.debug(" execute is a success");

replyStatus = callableStatement.getString(13);

} catch (Exception e) {

replyStatus = "100";

try {

dbConnection.rollback();

} catch (Exception ex) {

}

LogManager.error(

"Exception occurred createMarxAccount: " + e.getMessage());

} finally {

try {

if (callableStatement != null) {

callableStatement.close();

}

if (dbConnection != null) {

dbConnection.close();

}

} catch (Exception e) {

}

}

return replyStatus;

}

}

mciacciomenfia at 2007-7-29 > top of java,Application & Integration Servers,Application Servers...
# 3

this is included in web.xml

<resource-ref>

<res-ref-name>jdbc/MarxDB</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

cat sun-web.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sun-web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Servlet 2.3//EN' 'http://www.sun.com/software/sunone/appserver/dtds/sun-web-app_2_3-0.dtd'>

<sun-web-app>

<session-config>

<session-manager/>

</session-config>

<resource-ref>

<res-ref-name>jdbc/MarxDB</res-ref-name>

<jndi-name>jdbc/MarxDB</jndi-name>

</resource-ref>

<jsp-config/>

</sun-web-app>

mciacciomenfia at 2007-7-29 > top of java,Application & Integration Servers,Application Servers...
# 4

could you try

"java:comp/env/jdbc/MarxDB" for the lookup.

Jagadish.Prasatha at 2007-7-29 > top of java,Application & Integration Servers,Application Servers...