Tomcat JDBC连接在Eclipse中工作,但不是独立的 [英] Tomcat JDBC connection works in Eclipse but not stand-alone

查看:139
本文介绍了Tomcat JDBC连接在Eclipse中工作,但不是独立的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在进行升级我们的数据库软件以及从Tomcat 5.5到Tomcat 7的过程。因此,我使用一个新的JDBC驱动程序,在这种情况下推荐的SQL Anywhere JDBC 4.0驱动程序,它需要一个ODBC服务。



我已经取得了巨大的成功使这一切在Eclipse中工作。但奇怪的是,当我尝试在Eclipse外面运行Tomcat时,会出现以下错误:

  org.apache.tomcat。 dbcp.dbcp.SQLNestedException:无法创建PoolableConnectionFactory 
([Sybase] [JDBC驱动程序] [SQL Anywhere]数据库服务器未找到)

我可以获得一个纯Java驱动程序(jConnect)在两个环境中运行,所以我认为ODBC可能在这里扮演一个角色。但是jConnect是非常过时的,并有一些其他问题,所以我不想使用它。



这里是我的META-INF子目录中的context.xml片段

 < Context docBase =webpath =/ weboadable =false> 
<! - 访问数据库 - >
< Resource auth =Container
description =池连接到web数据库
maxActive =30maxIdle =5maxWait =10000name =jdbc / web
removeAbandoned =true
removeAbandonedTimeout =60
driverClassName =sybase.jdbc4.sqlanywhere.IDriver
type =javax.sql.DataSource
url =jdbc:sqlanywhere:DSN = testweb/>
< / Context>

相关的jar文件sajdbc4.jar位于$ {TOMCAT_HOME} / lib。我也试过将它添加到系统类路径,这没有什么区别。



Eclipse服务器使用自己的元数据空间数据,但我看到的唯一的显着差异是在Host标签内的server.xml中添加以下行:

 < Context docBase =webpath = / webreloadable =true
source =org.eclipse.jst.jee.server:web/>

我试过将这一行添加到我的独立安装,Tomcat反对。我也试过添加它减去Eclipse特定的source属性,它什么都不做。



我在Windows 7上运行,并试图关闭防火墙,相关。它似乎不是。 ODBC源是系统DSN,应该可供所有人访问。当我把一个伪造的DSN名称到Tomcat进行测试时,它告诉我它找不到它(一个不同的错误信息)。



花了很长时间这一点,我在一个完全的损失。我不想通过Java代码设置数据库,特别是因为它在Eclipse中工作,但生产将是一个独立的环境。

解决方案<



我已经找到一个解决方案,希望它可以拯救别人一些悲痛。有必要告诉SQL Anywhere JDBC驱动程序使用TCP / IP协议。您也不需要通过ODBC。我将数据库服务器作为独立进程运行,编制服务器名称testweb。然后我在资源定义中使用以下连接字符串:

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

诀窍。


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.

解决方案

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.

这篇关于Tomcat JDBC连接在Eclipse中工作,但不是独立的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆