This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Class not found exception.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Class not found exception.." Watch "Class not found exception.." New topic

Class not found exception..

Nagendra Shasthri
Ranch Hand

Joined: Nov 12, 2010
Posts: 35

HI All,

I am connecting to MS SQL 2005 server using Java code..I have jtds.jar file..But still I am getting class not found exceptiion...Wat could be the reason?Please help me..I have deadline to submit.

With Regards,
Nagendra Shasthri
Ranch Hand

Joined: Nov 12, 2010
Posts: 35

This is my java code...

import java.sql.*;
import javax.sql.*;

public class JDBCDemo{

public static void main(String args[]){
String dbtime;

//String dbUrl = "jdbc:jtds:sqlserver://";
//String dbClass = "com.mysql.jdbc.Driver";
String query = "Select * FROM EMPLOYEE_MASTER where EM_ID=356";

try {
System.out.println("Hello....");.....................This line is printing..
System.out.println("Hi..");..............It will not be printed.
Connection con = DriverManager.getConnection("jdbc:jtds:sqlserver://ktwo-19:1433;DatabaseName=KHRMS","sa", "Welcome12");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);

while ( {
String s = rs.getString("EM_USERNAME");


catch(ClassNotFoundException e) {

catch(SQLException e) {

} //end main

} //end class
James Boswell

Joined: Nov 09, 2011
Posts: 1051


It would be useful to see the stack trace of the exception. If nothing else, so we can see what class cannot be found.
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

the class net.sourceforge.jtds.jdbc.Driver could not be found, although you have jtds.jar file. Make sure the jar file is present in the classpath.

PM Me If You Want to get Urgent Help on Java Programming
Nagendra Shasthri
Ranch Hand

Joined: Nov 12, 2010
Posts: 35

@James and Nam..Thank you guys for your time..Ya I didn't set the class path..That was the problem..Solved it..:-)
Rob Spoor

Joined: Oct 27, 2005
Posts: 19914

And could you please UseCodeTags next time? It will preserve whitespace and add syntax highlighting, making code easier to read.

How To Ask Questions How To Answer Questions
It is sorta covered in the JavaRanch Style Guide.
subject: Class not found exception..