将Tomcat 5.5连接到SQL 2008时出现JDBC错误:我缺少什么? [英] JDBC error when connecting Tomcat 5.5 to SQL 2008: What am I missing?

查看:197
本文介绍了将Tomcat 5.5连接到SQL 2008时出现JDBC错误:我缺少什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的工作站(使用Eclipse运行)上的Tomcat 5.5实例连接到我的工作站上的SQL Express实例,我遇到了一些连接问题。

I'm attempting to connect a Tomcat 5.5 instance on my workstation (running with Eclipse) to a SQL Express instance on my workstation, and I'm having some connection issues.

我收到此异常:

Cannot create JDBC driver of class '' for connect URL 'null'

这是我的META-INF / context.xml:

Here's my META-INF/context.xml:

<Context>
  <Resource name="jdbc/SQLDB" auth="Container"
  type="javax.sql.DataSource" username="AppUser" password="password"
  driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" 
  url="jdbc:sqlserver://localhost;DatabaseName=AppUser;SelectMethod=cursor;"
  maxActive="8"/>
</Context>

而我的WEB-INF / web.xml:

And my WEB-INF/web.xml:

<resource-ref>
  <description>SQL Database Connection</description>
  <res-ref-name>jdbc/SQLDB</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

而我的来源:

InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/SQLDB");
Connection conn = ds.getConnection();

我也把sqljdbc4.jar文件放入Tomcat的common / lib文件夹。

I have also placed the sqljdbc4.jar file into Tomcat's common/lib folder.

一些Tomcat文档引用了将项目添加到server.xml文件中,而其他文档则没有;我不认为这是必要的,因为只有一个webapp将使用数据库。

Some of the Tomcat documentation references adding items to the server.xml file, and others do not; I don't think that's needed, given that only one webapp will be using the database. What am I missing, here?

推荐答案

这是人们把jar放在tomcat lib中的常见错误。 记住,始终将所有外部jar放在您的应用程序库中,即YourAppDir> WebContent> WEB-INF> lib

This is the common mistake that peoples put the jar in tomcat's lib. Remember always put all external jars in your apps lib i.e. YourAppDir>WebContent>WEB-INF>lib

第二件事是识别在eclipse的jar。请执行以下操作:

The second thing to do is to recognize the jar in eclipse. do that as follows:


  1. 在Eclipse中右键单击您的项目

  2. / li>
  3. 在属性窗口中点击JavaBuildPath

  4. 选择库选项卡

  5. 点击AddJARs按钮从项目的lib

  1. Right click on your project in Eclipse
  2. click on properties.
  3. on properties window click on JavaBuildPath
  4. select Libraries tab
  5. click AddJARs button & add the external jars from your project's lib

这篇关于将Tomcat 5.5连接到SQL 2008时出现JDBC错误:我缺少什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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