刚刚接触sqlServer,然后使用java创建一个maven项目获取连接
下面附上代码
首先是sqlServer的依赖
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
附上连接的代码
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class SqlServerConnect {
public static void main(String[] args) {
Connection connection = null;
PreparedStatement ps = null;
ResultSet rs = null;
try{
//加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//获取连接
connection = DriverManager.getConnection("jdbc:sqlserver://localhost;databaseName = test", "sa", "root");
//3.