DataSource is always null
843854Apr 9 2002 — edited Aug 4 2003Hi guys,
I need your help because the situation drives me crazy. I created web-application wich is connected with Oracle through DriverManager and it works well. Now I try to use DataSource but it's always null although there is no NamingException.
I simplified everything but it still doesn't work.
My simplified JSP-code looks like this:
Connection con;
String dbName = "java:comp/env/jdbc/myDB";
try {
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(dbName);
//con = ds.getConnection();
if(ds==null)
out.println("Datasource=null");
} catch (Exception ex) {
throw new Exception("Couldn't open connection to database: " + ex.getMessage());
}
This is my Tomcat configuration file fragment:
<Context path="/Leafs" docBase="Leafs" debug="0"
reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_Leafs_log." suffix=".txt"
timestamp="true"/>
<Environment name="maxExemptions" type="java.lang.Integer"
value="15"/>
<Parameter name="context.param.name" value="context.param.value"
override="false"/>
<Resource name="jdbc/myDB" auth="CONTAINER"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/myDB">
<parameter><name>user</name><value>sa</value></parameter>
<parameter><name>password</name><value>pw</value></parameter>
<parameter><name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value></parameter>
<parameter><name>driverName</name>
<value>jdbc:oracle:thin:@pdi.statestr.com:1521:myDB</value></parameter>
</ResourceParams>
</Context>
This is my web.xml:
<resource-ref>
<res-ref-name>jdbc/myDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Please help me I really need help.
Thank you in advance.
Qand