I have one Tomcat 5.5 with one resource for JDBC Pool connection:
<Resource name="jdbc/orcl"
auth="Container"
type="oracle.jdbc.pool.OracleDataSource"
drive开发者_如何学PythonrClassName="oracle.jdbc.driver.OracleDriver"
factory="oracle.jdbc.pool.OracleDataSourceFactory"
url="jdbc:oracle:thin:@myip:myport:mydatabase"
user="..."
password="...
implicitCachingEnabled="true"
connectionCachingEnabled="true"
connectionCacheProperties="{InitialLimit=10, MinLimit=10, MaxLimit=50, MaxStatementsLimit=0, ConnectionWaitTimeout=20}"
connectionCacheName="cacheOrcl"
/>
And I have the following code to obtain the Connection:
Object o = new InitialContext().lookup("java:comp/env/jdbc/orcl");
if( o instanceof DataSource ) {
DataSource ds = (DataSource) o;
con = ds.getConnection();
LOGGER.debug(ds);
}
The interesting is that is working on a JSP, but not in one Spring Controller. In the spring controller I receive the message:
Name jdbc is not bound in this Context
org.apache.naming.NamingContext NamingContext.java 770 lookup
org.apache.naming.NamingContext NamingContext.java 153 lookup
org.apache.naming.factory.ResourceLinkFactory
I don't know why the issue occurs, but I can suggest a better way to use jdbc with spring - using JdbcTemplate and the spring jdbc support - see here for a manual
精彩评论