Kevin Wu
Kevin Wu

Reputation: 1477

java.sql.SQLException: No suitable driver found for jdbc:sqlserver... (intellij, maven)

I have the above error and am wondering what to do. I have done the following things already:

  1. downloading the sqljdbc4.jar from Microsofts website
  2. installing it to my local maven repository
  3. including it in pom.xml like this:

    com.microsoft.sqlserver sqljdbc4 4.0

Since I am using jdbc4, I read that I do not have to call Class.forName, but can build the connection to the database directly. So why do I still get the nosuitabledriver error?

EDIT: When using ClassForName like below, I get a ClassNotFoundException.

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); //I also tried Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
String dbURL = "jdbc:sqlserver://localhost;databaseName=test;integratedSecurity=trues";
conn = DriverManager.getConnection(dbURL);

Upvotes: 1

Views: 4538

Answers (2)

Kevin Wu
Kevin Wu

Reputation: 1477

I added the external module to main now instead of the project directory. I assume that I need to do the latter before I deploy the application. But now, the error is gone.

Upvotes: -1

Ye Win
Ye Win

Reputation: 2098

First you need to make sure your Driver classpath to correct classpath:

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

Changed to:

 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

Second you need to make sure your dbURL to correct dbURL:

String dbURL = "jdbc:sqlserver://localhost;databaseName=test;integratedSecurity=trues";

Change to:

String dbURL = "jdbc:sqlserver://localhost:1443;databaseName=test;integratedSecurity=trues";

Third, add your DB username and password in getConnection method:

conn = DriverManager.getConnection(dbURL);

Change to:

conn = DriverManager.getConnection(dbURL,"yourUserName","yourPass");

hope it helps.

Upvotes: 2

Related Questions