| Author |
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,
Shastry
|
 |
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://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
Ranch Hand
Joined: Nov 09, 2011
Posts: 657
|
|
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
Joined: Oct 31, 2011
Posts: 347
|
|
|
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.
|
Job Offer: Online working Java technical writing
|
 |
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
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
And could you please UseCodeTags next time? It will preserve whitespace and add syntax highlighting, making code easier to read.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Class not found exception..
|
|
|