无法在Eclipse中引用jdbc.SQLServerDriver(ClassNotFoundException) [英] Cannot reference jdbc.SQLServerDriver in Eclipse (ClassNotFoundException)
问题描述
我正在尝试将MSSQL驱动程序用于JDBC.我已按照有关如何将外部JAR文件添加到Eclipse Windows IDE的说明进行操作,如下所示:
-从此处下载安装 http://msdn.microsoft.com/zh- us/sqlserver/aa937724.aspx (用于SQL Server的Microsoft JDBC驱动程序4.0)
-将zip解压缩到我在此处解压缩的文件位置(c:\ MsJDBCforSqlDriver)
-在Eclipse Package Explorer中,右键单击您的项目->构建路径->配置构建路径-> Java构建路径->库选项卡-添加外部JAR文件,然后浏览至
"C:\ MsJDBCforSqlDriver \ sqljdbc_4.0 \ enu \ sqljdbc4.jar"
-然后,我如下图所示查看成功的引用,其中包括SQLServerDriver.class
I am trying to use the MSSQL driver for JDBC. I have followed the instructions on how to add an external JAR file to the Eclipse Windows IDE as follow:
- Download the installation from here http://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx (Microsoft JDBC Driver 4.0 for SQL Server)
- Extract the zip to a file location I have extracted it here (c:\MsJDBCforSqlDriver)
- In Eclipse Package Explorer right click your project -> Build Path -> Configure Build Path -> Java Build Path -> Libraries Tab- Add External JAR file and then I browse to
"C:\MsJDBCforSqlDriver\sqljdbc_4.0\enu\sqljdbc4.jar"
- I then view the successful reference as in image below including SQLServerDriver.class
当我尝试执行Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")时,出现ClassNotFound异常,如下所示:
When I try to execute Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver") I get a ClassNotFound Exception as below:
我尝试了所有可以在Google上找到的建议,包括在Windows环境变量中设置类路径.
I tried all suggestions I could find on Google including setting the classpath in Windows Environment Variables.
推荐答案
我在这里找到了答案: http://code.google.com/p/android/issues/detail?id=27490 似乎引用库"下的包含"在运行时不可用,我看不到如何在我的Eclipse版本中更改它
I found the answer here: http://code.google.com/p/android/issues/detail?id=27490 Seems like includes under Referenced Libraries is not available at runtime and I couldn't see how to change this in my version of Eclipse
" 由fred ... @ mobileinteraction.se报道,2012年3月22日 主机操作系统:Windows 7 x64 SDK工具版本:17 Eclipse版本:3.7.2 ADT插件版本:17.0.0v201203161636-291853 您的项目目标平台:2,2 在仿真器中运行的平台版本:2.2
" Reported by fred...@mobileinteraction.se, Mar 22, 2012 Host OS: Windows 7 x64 SDK tools version: 17 Eclipse version: 3.7.2 ADT plug-in version:17.0.0v201203161636-291853 Platform targeted by your project: 2,2 Version of the platform running in the emulator: 2.2
要复制的步骤: 1.创建一个使用外部jar的项目(在我的情况下为android-support-v4.jar). 2.使用属性-Java构建路径-添加外部Jar添加了android-support-v4.jar.让Activity从FragmentActivity扩展. 3.清理并运行项目
STEPS TO REPRODUCE: 1. Create a project that uses external jars (in my case android-support-v4.jar ). 2. Added the android-support-v4.jar using Properties - Java Build Path - Add External Jar. Have the Activity extends from FragmentActivity. 3. Clean and run project
预期结果:应用程序将运行,启动FragmentActivity
EXPECTED RESULTS: Application would run launching the FragmentActivity
观察到的结果:应用程序崩溃,android-support-v4.jar被放置在参考库"中,因此Android在运行时找不到它.
OBSERVED RESULTS: Application crashes, android-support-v4.jar is placed within "References Libraries" and thus Android can't find it at runtime.
解决方案: 在项目中手动创建一个文件夹/libs,将android-support-v4.jar复制到该文件夹,ADT会将其放置在"Android Dependencies"下,并且可以正常工作.
SOLUTION: Manualy create a folder /libs within your project, copy the android-support-v4.jar to that folder and the ADT will place it under 'Android Dependencies' and it works.
使用属性-Java构建路径-添加外部Jar"添加的所有外部jar都是这种情况.
This is the case for all external jars added using Properties - Java Build Path - Add External Jar.
"
这篇关于无法在Eclipse中引用jdbc.SQLServerDriver(ClassNotFoundException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!