File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes No suitable driver found for jdbc:jtds:sqlserver://localhost:1433/db Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "No suitable driver found for jdbc:jtds:sqlserver://localhost:1433/db " Watch "No suitable driver found for jdbc:jtds:sqlserver://localhost:1433/db " New topic
Author

No suitable driver found for jdbc:jtds:sqlserver://localhost:1433/db

lalit khera
Ranch Hand

Joined: Jun 06, 2012
Posts: 36
hi friends. i know its a very common error and so many solutions are available on the web.
I tried most of them but not able to resolve this error.
here is the error i got ----- No suitable driver found for jdbc:jtds:sqlserver://localhost:1433/db

Let me tell you that i am using Windows 7 64 bit os, so jdbc-odbc doesnt helped me, thats why i am using JTDS Driver.
I have set the classpath as
variable name: classpath
variable value: C:\Tomcat 7.0\lib\servlet-api.jar;C:\Tomcat 7.0\lib\catalina.jar;C:\Tomcat 7.0\webapps\bugtrack\WEB-INF\lib;C:\Program Files\jtds\jtds-1.2.5.jar;
I am using SQL server 2008 R2 as the database.
And here is the code that i am using----

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.net.*;

public class HelloServlet extends HttpServlet {

Connection theConnection;
private ServletConfig config;
public void init(ServletConfig config) throws ServletException
{
this.config = config;
}
public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
HttpSession session =req.getSession(true);
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try
{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
out.print("hello");
try{
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
}catch (ClassNotFoundException e) {
e.printStackTrace();
}
theConnection = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/db", "sa", "Passw0rd");
Statement theStatement = theConnection.createStatement();
ResultSet theResult = theStatement.executeQuery("select * from usertable");
while(theResult.next())
{
out.println(""+theResult.getString(1)+"");
out.println(""+theResult.getString(2)+"");
out.println(""+theResult.getString(3)+"");
}
theResult.close();
theStatement.close();
theConnection.close();
}catch(Exception e)
{
out.println(e.getMessage());
}
}

}

i am not using any IDE, i am doing all stuff at the command prompt.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: No suitable driver found for jdbc:jtds:sqlserver://localhost:1433/db