Accepted answer

the problem is with class.forname(""); this line. the class qualified name is wrong

it is sqlserver.jdbc not jdbc.sqlserver


just change the query like this:

select top 1 * from [humanresources].[employee]

where employee is your table name and humanresources is your schema name if i am not wrong.

hope your problem will be resolved. :)


add sqlserver.jar here is link

as the name suggests classnotfoundexception in java is a subclass of java.lang.exception and comes when java virtual machine tries to load a particular class and doesn't found the requested class in classpath.

another important point about this exception is that, it is a checked exception and you need to provide explicitly exception handling while using methods which can possibly throw classnotfoundexception in java either by using try-catch block or by using throws clause.

oracle docs

public class classnotfoundexception
 extends reflectiveoperationexception

thrown when an application tries to load in a class through its string name using:

  • the forname method in class class.
  • the findsystemclass method in class classloader .
  • the loadclass method in class classloader.

but no definition for the class with the specified name could be found.


the link has the driver for sqlserver, download and add it your eclipse buildpath.


right click your project--->build path---->configure build path----> libraries tab--->add external jars--->(navigate to the location where you have kept the sql driver jar)--->ok


download microsoft jdbc driver 4.0 for sql server which supports:

    sql server versions: 2005, 2008, 2008 r2, and 2012.
    jdk version: 5.0 and 6.0.

run the downloaded program sqljdbc__.exe. it will extract the files into a specified directory (default is microsoft jdbc driver 4.0 for sql server). you will find two jar files sqljdbc.jar (for jdbc 3.0) and sqljdbc4.jar (for jdbc 4.0), plus some .dll files and html help files.

place the sqljdbc4.jar file under your application’s classpath if you are using jdk 4.0 or sqljdbc4.1.jar file if you are using jdk 6.0 or later.


refer the below link.

there are two important changes that you should make

driver name as ""

& in url "jdbc:sqlserver://localhost:1433"+";databasename=adventureworks2008r2"


you forgotten to add the sqlserver.jar in eclipse external library follow the process to add jar files

  1. right click on your project.
  2. click buildpath
  3. click configure bulid path
  4. click add external jar and then give the path of jar

Related Query

More Query from same tag