Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class not found exception..

 
Nagendra Shasthri
Ranch Hand
Posts: 35
Chrome Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nagendra Shasthri
Ranch Hand
Posts: 35
Chrome Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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://192.168.1.109:1433/KHRMS";
//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..
Class.forName("net.sourceforge.jtds.jdbc.Driver");
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 (rs.next()) {
String s = rs.getString("EM_USERNAME");
System.out.println(s);
}

con.close();
}

catch(ClassNotFoundException e) {
e.printStackTrace();
}

catch(SQLException e) {
e.printStackTrace();
}

} //end main

} //end class
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nagendra

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
Posts: 504
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nagendra Shasthri
Ranch Hand
Posts: 35
Chrome Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And could you please UseCodeTags next time? It will preserve whitespace and add syntax highlighting, making code easier to read.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic