Reputation: 79
I have my Selenium tests written in java (Eclipse). I connect to SQL Server and verify some results in database, using JDBC SQLServerDriver; The tests run perfectly in Eclipse : (Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver).newInstance();
).
While I need to execute them via command line I run the following line:
mvn clean install -Dtest=Test1 test
The test gets executed only until it has to connect SQL Server to verify the data. I get error message that says:
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://DBALIASSTAGING:1433 at java.sql.DriverManager.getConnection(DriverManager.java:689)
I point to JDK 1.8 in Eclipse and in my JAVA_HOME
. I have my sqljdbc4.jar
pointed at in Eclipse and in CLASSPATH
(C:\Microsoft JDBC Driver 4.0\sqljdbc_4.0\enu\sqljdbc4.jar
).
Anything else I am missing? The weird thing is the Test1 runs very well- connects and searches database within Eclipse only. But fails to connect SQL Server via command line, when I run mvn clean install -Dtest=Test1 test
. The run well, but chokes when need to connect to SQL Server (11).
I have read all the posts on sqljdbc4.jar
and set up the CLASSPATH
variable properly and couldn't find anything wrong in my configuration.
Please give me a clue or a hint, I am totally lost, what am I doing wrong?
Upvotes: 2
Views: 1223
Reputation: 407
This is quite tricky as far as I know Microsoft has not released that jar into any maven repositories.
First of all, the fact that you have the jar in eclipse classpath means nothing for Maven (it's independent). Maven will require you to have a dependency in the pom.xml of the project in order to use the jar. (works similarly as the eclipse classpath).
Like this:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
Notice the scope test means that the jar will only be available for maven when testing.
Now, the dependency is usually downloaded from maven central repository. Since it is not there, you will have to download it from microsoft and install it yourself using:
mvn install:install-file -Dfile=sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0 -Dpackaging=jar
Missing artifact com.microsoft.sqlserver:sqljdbc4:jar:4.0
Please also check the other answer regarding JTDS. This library (it's openly available on maven) is one that I have successfully used in multiple production running software.
More info on maven dependencies: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
Upvotes: 1