Erica Kane
Erica Kane

Reputation: 3352

Tomcat JDBC connection works in Eclipse but not stand-alone

We are going through the process of upgrading our database software and also going from Tomcat 5.5 to Tomcat 7. As a result I am using a new JDBC driver, in this case the recommended SQL Anywhere JDBC 4.0 driver, which requires an ODBC service.

I have had great success getting this all to work in Eclipse. But strangely enough, when I try to run Tomcat outside of Eclipse, I get the following error:

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory
([Sybase][JDBC Driver][SQL Anywhere]Database server not found)

I can get a pure Java driver (jConnect) to run in both environments, so I think the ODBC may be playing a role here. However jConnect is very outdated and has some other issues so I don't want to use it.

Here is the context.xml snippet from my META-INF sub-directory under my web application:

<Context docBase="web" path="/web" reloadable="false">
  <!-- Access to the database -->
  <Resource auth="Container" 
    description="Pooled connection to the web database" 
    maxActive="30" maxIdle="5" maxWait="10000" name="jdbc/web" 
    removeAbandoned="true" 
    removeAbandonedTimeout="60" 
    driverClassName="sybase.jdbc4.sqlanywhere.IDriver"
    type="javax.sql.DataSource" 
    url="jdbc:sqlanywhere:DSN=testweb" />
</Context>

The relevant jar file, sajdbc4.jar, is located in ${TOMCAT_HOME}/lib. I also tried adding it to the system classpath, which made no difference.

The Eclipse server is using its own metaspace data, but the only significant difference I've seen is the addition of the following line to server.xml within the Host tag:

<Context docBase="web" path="/web" reloadable="true" 
source="org.eclipse.jst.jee.server:web"/>

I tried adding this line to my stand-alone installation, and Tomcat objected. I also tried adding it minus the Eclipse-specific source attribute, and it did nothing.

I am running on Windows 7 and have tried turning off the firewall in case that was relevant. It does not seem to be. The ODBC source is a System DSN and should be accessible to all. When I put a bogus DSN name to Tomcat to test, it tells me it can't find it (a different error message).

At this point, I've spent a very long time on this and am at a complete loss. I'd rather not set up the database via Java code especially as it IS working in Eclipse, but production is going to be a standalone environment.

Upvotes: 1

Views: 1820

Answers (1)

Erica Kane
Erica Kane

Reputation: 3352

I have found a solution, and hope it may save others some grief.

It is necessary to tell the SQL Anywhere JDBC driver to use the TCP/IP protocol explicitly. You also don't need to go through ODBC. I run the database server as a stand-alone process, braodcasting a server name "testweb". Then I use the following connection string in my Resource definition:

url="jdbc:sqlanywhere:Server=testweb;UID=xxx;PASSWORD=xxx;port=2638;LINKS=tcpip(PORT=2638)"

And that does the trick.

Upvotes: 1

Related Questions