File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes ClassNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "ClassNotFoundException" Watch "ClassNotFoundException" New topic


cesar aviles

Joined: Aug 14, 2007
Posts: 3
First off I would like to say everyone on this forum seems to be full of knowledge. I have been using it for only a few days but it has helped me out a lot. This is my first question I'm going to ask. I'm new to java.

I am recieving an error. When I run my app. The error states.
java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver

I come from a .NET background where we don't have to register odbc drivers or at last I've never had to. I really like Java mainly because it's cross platform. Does anyone know what I can do to resolve this? I highly doubt the issue is in my code but here it is.

public static void main(String[] args) {
String url = "jdbc:jtds:sqlserver://localhost:1433/hello";
Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/hello", "sa", "password");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from Employee");



catch(ClassNotFoundException excp)

catch(SQLException exp)

Thanks in advance guys,

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Welcome to JavaRanch.

The code seems fine indeed, but you need to have the JDBC driver (the jar file that contains the jTDS classes) in your classpath. Onbe wya to do that would be to start your program with something like the following, where "jtds.jar" would be replaced by the path and name of the jar file.

I agree. Here's the link:
subject: ClassNotFoundException
It's not a secret anymore!