Hi guys,
After reading
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
and
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
I am still trying to configure tomcat 6.0.20 to use datasources.
I could be doing something very wrong and silly but cannot realize what.
Here are the relevant parts of my project:
=================================================
0. The web app is called test
1. web.xml in WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<resource-ref>
<description>My postgreSQL Datasource</description>
<res-ref-name>MyDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
2. context.xml in META-INF (I undeploy and redeploy the app in order to
not use previous context.xml files)
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/test">
<Resource name="MyDS"
auth="Container"
type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://myhost:5432/mydb"
username="myusername"
password="mypassword"
maxActive="20"
maxIdle="10"
maxWait="-1"/>
</Context>
3. index.jsp :
<%@ page language="java" contentType="text/html;charset=UTF-8"
import="java.util.*, java.io.*, javax.naming.*"
%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=UTF-8"/>
<TITLE>Datasource information</TITLE>
</HEAD>
<BODY >
<table >
<tr><td>Name</td>
<td>Exists</td>
<td>Type</td>
<td>toString</td>
</tr>
<%
try {
Context initCtx = new InitialContext();
Context envCtx = (Context)
initCtx.lookup("java:comp/env");
String[] sources = {"MyDS"};
for (int i =0; i<sources.length; i++){
Object ds = envCtx.lookup(sources[i]);
boolean exist = (null == ds);
String className
=(exist)?ds.getClass().getName():"NULL";
String show = (exist)?ds.toString():"NULL";
%>
<tr>
<td><%=sources[i]%></td>
<td><%=exist%></td>
<td><%=className%></td>
<td><%=show%></td>
</tr>
<%
}
} catch (Exception e) { %>
<tr>
<td>
<%= e.toString() %>
</td>
</tr>
<%
}
%>
</table>
</BODY>
</HTML>
4. The lib dir of tomcat contains the postgres JDBC driver jar.
=================================================
The result that I get is when I open the index.jsp page is:
Name Exists Type toString
MyDS false NULL NULL
What am I missing? How can I check what is going wrong?
Kind regards:
al_shopov
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]