This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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: 41626
    
  55
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