This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Class not found exception.." Watch "Class not found exception.." New topic
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
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

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: 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
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
Don't get me started about those stupid light bulbs.
 
subject: Class not found exception..
 
Similar Threads
NEW SCEA Mock Test Available!!
Remote Interface
NullPointerException in hibernate
Jasper Report and JAR file
custom class loader