Menu

#2 Datasource and Tomcat plugin

open
nobody
None
5
2003-11-14
2003-11-14
Frank Wolfe
No

Hello,

I am attempting to use a datasource in my project but
am having trouble getting it set up. Within Tomcat
itself I get it to work fine.

I have placed my database jar in the
<eclipse>/plugins/com.blueskytime.eclipse.tomcat_0.9.0

editted my server.xml to look somnething like this:

<Context crossContext="true" debug="0"
docBase="C:/eclipse-SDK-2.1-win32/eclipse/workspace/inap"
path="" reloadable="true"
workDir="C:/eclipse-SDK-2.1-win32/eclipse/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/inap/com.blueskytime.eclipse.webapp/work">
<Resource auth="Container" name="jdbc/InapDb"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/InapDb">
<parameter>
<name>user</name>
<value>inap</value>
</parameter>
<parameter>
<name>password</name>
<value>password</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.inet.tds.TdsDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:inetdae:fwolfe2:1433</value>
</parameter>
</ResourceParams>
<Resource auth="Container" name="jdbc/InapDb2"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/InapDb2">
<parameter>
<name>maxActive</name>
<value>5</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>5</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>user</name>
<value>inap</value>
</parameter>
<parameter>
<name>password</name>
<value>password</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.inet.tds.TdsDriver</value>
</parameter>
<parameter>
<name>driverName</name>
<value>jdbc:inetdae:fwolfe2:1433</value>
</parameter>
</ResourceParams>
</Context>

Added this to my web.xml:
<resource-ref>
<description>
Resource reference to a factory for java.sql.Connection
instances that may be used for talking to a particular
database that is configured in the server.xml file.
</description>
<res-ref-name>
jdbc/InapDb2
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>

I then am doing a simple jsp page to test it.

<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingEnumeration" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.sql.*" %>

<%

Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");

DataSource ds = (DataSource)envCtx.lookup("jdbc/InapDb2");

Connection conn = ds.getConnection();

%>
It finds the look up fine but bombs getting the
datasource. I am sure it has to do with the plugin not
finding the jars, but how or where do I add them so the
tomcat plugin/Eclipse IDE knows to use them.

Did the same in a standlone Tomcat and everything
worked fine.

Any Help would be appreciated.

Frank Wolfe
frank.wolfe@bpd.treas.gov
frank.wolfe@charter.net

Discussion


Log in to post a comment.

MongoDB Logo MongoDB