Trisummit Technologies

java.sql.SQLException: No suitable driver – JDBC

Posted on | May 21, 2009 | 1 Comment

This should be a very simple problem, but finding the solution does not always jump out at you based on the tutorials out there.

When doing a JDBC connection for SQL Server you may have the following line of code:


String sqlServerConnectionString = "jdbc:sqlserver://10.0.0.233:1433; 
databaseName=mydatabasename;user=sa;password=mypassword";
Connection con = DriverManager.getConnection(sqlServerConnectionString);

Then you go to run it and run into the following:
java.sql.SQLException: No suitable driver

Actually, the problem is very simple. Earlier on, you may have forgotten this:


try
{
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e)
{
    System.out.println(e);
}
try
{
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e)
{
    System.out.println(e);
}

//Now run the code you originally ran:
String sqlServerConnectionString = "jdbc:sqlserver://10.0.0.233:1433;
databaseName=mydatabasename;user=sa;password=mypassword";
Connection con = DriverManager.getConnection(sqlServerConnectionString);

That should either solve your problem or at least give you a hint of what to do next.

Comments

One Response to “java.sql.SQLException: No suitable driver – JDBC”

  1. pisce
    October 5th, 2009 @ 5:24 pm

    I think it also happens when you do not configure your database connection in your persistence.xml – I faced this error on a WebLogic 10

Leave a Reply