Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot reference jdbc.SQLServerDriver in Eclipse (ClassNotFoundException)

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

enter image description here

When I try to execute Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver") I get a ClassNotFound Exception as below:

enter image description here

I tried all suggestions I could find on Google including setting the classpath in Windows Environment Variables.

like image 756
Pierre Avatar asked Jan 27 '26 10:01

Pierre


2 Answers

Under the Run -> Run Configurations menu item you should find an entry for a Java application with the same name as the class that contains your main() method.

Have a look at the classpath tab. You should find your project listed under user entries. Expand it and see if the Microsoft JDBC Jar is listed.

The class path you use for compilation need not be the same as you choose for runtime, though Eclipse usually mirrors any changes to your build path to any launch configurations.

Your spelling and case for the package and class names look correct (Java is case-sensitive on names).

And yes, learning Java and Eclipse will take effort - Eclipse is quite different from other IDEs and it takes time to get to know it.

like image 112
SteveD Avatar answered Jan 28 '26 22:01

SteveD


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

" Reported by [email protected], 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

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

EXPECTED RESULTS: Application would run launching the FragmentActivity

OBSERVED RESULTS: Application crashes, android-support-v4.jar is placed within "References Libraries" and thus Android can't find it at runtime.

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.

This is the case for all external jars added using Properties - Java Build Path - Add External Jar.

"

like image 34
Pierre Avatar answered Jan 28 '26 22:01

Pierre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!