com.mysql.jdbc.driver class not found exception

I took help from this blog post:

But I get com.mysql.jdbc.driver class not found exception. What’s different in that blog post was that they’ve tried to connect to mysql instead of MS SQL in my case. Here’s my code so far:
package com.example.dbtry;

  • How to update more than one column in SQL?
  • Find out how long the sql server service has been running, from t-sql
  • How to open a second report from original on ssrs
  • Remove duplicate entries from Table
  • Get column names/types returned from a stored procedure
  • PerformancePoint dashboard permissions problem in MOSS
  • public class MainActivity extends Activity {
    protected TextView tv;
    private static final String url = "jdbc:jtds:sqlserver://";
    private static final String user = "username";
    private static final String pass = "password";
    protected void onCreate(Bundle savedInstanceState) {
    public void testDB() {
        tv = (TextView)findViewById(;
         try {
                Connection con = DriverManager.getConnection(url, user, pass);
                /* System.out.println("Database connection success"); */
                String result = "Database connection success\n";
                Statement st = con.createStatement();
                ResultSet rs = st.executeQuery("select * from this_table");
                ResultSetMetaData rsmd = rs.getMetaData();
                while( {
                    result += rsmd.getColumnName(1) + ": " + rs.getInt(1) + "\n";
                    result += rsmd.getColumnName(2) + ": " + rs.getString(2) + "\n";
                    result += rsmd.getColumnName(3) + ": " + rs.getString(3) + "\n";
            catch(Exception e) {
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(, menu);
        return true;

    Please tell me what I’m doing wrong. I have also added permission to the Internet in the manifest.

    5 Solutions collect form web for “com.mysql.jdbc.driver class not found exception”

    download the jar from:
    then change these lines as below:

    private static final String url = "jdbc:sqlserver://";

    Download the JTDS driver from here and include it in your classpath. Build and run your code. It’ll work.

    You’re missing the Mysql Connection JAR on your classpath.

    This jar contains the driver: com.mysql.jdbc.Driver

    However as you are using MSSQL and not MySQL I suggest you find a suitable driver for MSSQL instead.

    I guess there is a problem with the url stated.

    try running on the local host first and then give the correct url that you have. “jdbc:mysql://localhost:3306/databaseName”

    You are loading the class for MYSQL DB connection, you should load the class for MS SQL and should include the required jar files in the build path.
    Edit the Class.forName line as below:

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.