-1

I followed this answer How to use JNDI DataSource provided by Tomcat in Spring? but I am gettin the following exception :

java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:524)
at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:493)
at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
at java.sql.DriverManager.getDriver(DriverManager.java:273)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:224)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:120)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:143)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:132)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

tomcat server.xml :

<GlobalNamingResources>
<Resource 
    name="jdbc/welcome-kit"
    global="jdbc/welcome-kit"       
    auth="Container" 
    type="javax.sql.DataSource" 
    username="name" 
    password="pass" 
    driverClassName="oracle.jdbc.driver.OracleDriver"
    url="host/port:test" 
    maxActive="8" 
    maxIdle="4"
/>

tomcat context.xml

<ResourceLink global="jdbc/welcome-kit" name="jdbc/welcome-kit" type="javax.sql.DataSource" />

web application web.xml:

<resource-ref>
 <description>DB Connection</description>
 <res-ref-name>jdbc/welcome-kit</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>

spring-context.xml:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/jdbc/welcome-kit">
</bean>

and also i have added ojdbc.jar in tomcat/lib

Community
  • 1
  • 1
ekim
  • 91
  • 11

1 Answers1

0

In web.xml

<resource-ref>
    <res-ref-name>myDatasource</res-ref-name>
    <res-type>javax.sql.XADataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

In your spring application context :

<!-- Define the JNDI datasource -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/myDatasource" />
</bean>
Gab
  • 7,869
  • 4
  • 37
  • 68
  • as you declared the datasource in global namespace you have to resolve it using `java:/jdbc/welcome-kit` – Gab Jan 20 '15 at 12:55
  • appears other error Caused by: javax.naming.NameNotFoundException: Name [jdbc/welcome-kit] is not bound in this Context. – ekim Jan 20 '15 at 13:19
  • hmm so the previous JNDI name was correct and your error is not related to JNDI lookup. It seems the used driver is a jdbc-odbc bridge whereas you're specifying an oracle JDBC driver class in datasource declaration. try to download and provide a suitable driver (http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html) – Gab Jan 20 '15 at 13:28