Hi all,

I am trying run a java class how obtain the datasource by jndi.

I use a jboss-4.0.2 where I have the datasource like this...

Java Code:
<local-tx-datasource>
                <jndi-name>MY_POOL</jndi-name>
                <connection-url>jdbc:oracle:thin:@192.168.15.22:1550:MyDB</connection-url>
                <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
                <user-name>username</user-name>
                <password>passwname</password>
                <use-java-context>false</use-java-context>
                <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>

                <min-pool-size>5</min-pool-size>
                <max-pool-size>20</max-pool-size>
                <idle-timeout-minutes>5</idle-timeout-minutes>

                <metadata>
                        <type-mapping>Oracle9i</type-mapping>
                </metadata>
        </local-tx-datasource>
the jnp port is 6578

And I have created the next class to test the jndi connection:
Java Code:
package connections;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class TestJNDI {

	public static void main(String[] args) {
		
		Properties p = new Properties();

		p.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory" ) ;
		p.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" ) ;
		p.setProperty("java.naming.provider.url","jnp://192.168.15.22:6578") ;
		
        try {
        	Context ctx = null;
        	ctx = new InitialContext(p);          
                DataSource _dataSource = (DataSource) ctx.lookup("MY_POOL");

        	Connection dbConn = _dataSource.getConnection();                      
        	System.out.println(dbConn.getTransactionIsolation());            
        	PreparedStatement pstmt = dbConn.prepareStatement("SELECT SYSDATE FROM DUAL");

        	ResultSet rs = pstmt.executeQuery();
        	String valor ="";

        	while(rs.next()){
        		valor = rs.getString("SYSDATE");
        	}

            pstmt.close();                                                                                                                               
            dbConn.close();

            System.out.println("==>>"+valor);
        } catch (Exception e) {
        	e.printStackTrace();
        }           
	}
}
When I execute this, I have a error in the line
Java Code:
DataSource _dataSource = (DataSource) ctx.lookup("MY_POOL");
The error:
Java Code:
java.lang.ClassCastException
	at connections.TestJNDI.main(TestJNDI.java:36)
Why this error??

Thanks.