How to connect sql server through java code?

南楼画角 提交于 2019-12-01 11:46:08

Your dependency's scope is test, which means it will not be in the classpath when the application runs normally (not as a test). Change the scope to runtime, in which case classes inside the .jar will be available in run-time both if you run the application in the IDE or use a Maven plugin to package it.

If you are still facing the issue with maven , you can download sqlserver jar file separately and add it in your project and try to run again.below is the path to download jar file.

http://java2s.com/Code/Jar/s/Downloadsqlserverjdbcjar.htm

Unfortunately Microsoft doesn't make this artifact available via any maven repository . I would suggest you to use below dependency to resolve your issue

Microsoft has published some their drivers to maven central:

 <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>6.1.0.jre8</version>
        </dependency>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!