• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassNotFoundException

 
cesar aviles
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic