0

This is a repeated question but I did everything right as mentioned. I have added following maven repo dependency to pom.xml of my project:

  <dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>6.1.0.jre8</version>
    <scope>test</scope>
</dependency>

And this is my java code running on 1.8.0_144:

    package com.demo;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.Statement;

    public class Test {
    Connection con;
    Statement st;
    PreparedStatement ps;

     Test(){
          try {
                            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con =       DriverManager.getConnection("jdbc:sqlserver://localhost:1521;user=SYSTEM;password=oracle;sid=xe");
            if(con != null) {
                System.out.println("Connected to MSsql !!");
            }

            //st = con.createStatement();


        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {

        new Test();
        System.out.println(System.getProperty("java.version"));
    }
}

1 Answer 1

2

Most probably test scope is not appropriate, if you're running your code not as a maven test.

Try to change the scope to <scope>compile</scope>.

If it does not help, please post or submit the whole project, so the case would be reproducible.

You can read about the scopes here http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope.

Sign up to request clarification or add additional context in comments.

2 Comments

That gave me a different error, so thats solved. Thank you.
@Dexter Your JDBC URL contains reference to Oracle things. You may want to check the Microsoft SQL Server JDBC documentation for the correct URL format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.