wood burning stoves 2.0*
The moose likes JDBC and the fly likes ClassNotFoundException 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 "ClassNotFoundException" Watch "ClassNotFoundException" New topic
Author

ClassNotFoundException

cesar aviles
Greenhorn

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) {
try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
String url = "jdbc:jtds:sqlserver://localhost:1433/hello";
Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/hello", "sa", "password");
//connection="jdbc:jtds:sqlserver://localhost:1433/hello;user="+user+";password="+password;
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from Employee");

while(rs.next())
{
System.out.println(rs.getString(1));
}

st.close();
conn.close();

}
catch(ClassNotFoundException excp)
{
System.out.println(excp.toString());
}

catch(SQLException exp)
{
System.out.println(exp.toString());
}

Thanks in advance guys,

Cesar
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41015
    
  43
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.



Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassNotFoundException
 
Similar Threads
Connecting SQL Server 2000 Thru type4 Driver
Class not found exception..
Connect to db, simple question !!
JApplet not connecting to SQL database
ms sql question