at first, I retrieve the datasource and the connection using these two methods where ds is an attribut of my class DBManager : public DataSource ds = null;
this is the constructor used by getInstance method to have a singelton :
private DBManager() throws NamingException {
logger.debug("Begin DBManager()");
Context initContext = new InitialContext();
Object obj = initContext.lookup("MyDS");
logger.debug("objref class= " + obj.getClass());
logger.debug("objref class= " + obj.getClass().getClassLoader());
ds= (DataSource) obj;
logger.debug("End DBManager()");
}
public final Connection getConnection() throws SQLException {
logger.debug("Begin getConnection()");
Connection conn = null ;
if (ds != null) {
try {
conn = (Connection) ds.getConnection();
conn.setAutoCommit(false);
} catch (SQLException e) {
e.printStackTrace();
logger.error("Fail to create connecxion "+ e.getMessage());
}
} else {
logger.warn("Data Source is null");
}
logger.debug("End getConnection()");
return conn;
}
this is the myDS-ds.xml descriptor :
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== -->
<datasources>
<local-tx-datasource>
<jndi-name>MyDS</jndi-name>
<!-- Using global namespace. In this case, JNDI name of Oracle DS is OracleDS -->
<use-java-context>false</use-java-context>
<connection-url>
jdbc racle:thin:@152.148.10.160:1521
rcl</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>auto</user-name>
<password>auto</password>
<connection-property name="char.encoding">UTF-8</connection-property>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
</local-tx-datasource>
</datasources>
this is the trace :
[08/mars/2007 16:37:54:859] DEBUG: com.solutions.auto.persistence.connection.DBManager.getConnection : End getConnection()
java.lang.ClassCastException: $Proxy3
at com.solutions.auto.persistence.indicator.IndicatorDaoImpl.selectIndicators(IndicatorDaoImpl.java:81)
at com.solutions.auto.persistence.indicator.TestIndicatorDaoImpl.testSelectIndicators(TestIndicatorDaoImpl.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Thank you
Adil