1.先下载sqlserver的jar,注意我用jdk8下
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.2.2.jre8</version>
</dependency>
2.加载sqlserver的jdbc参数
DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
BasicDataSource sqlserverDataSource = new BasicDataSource();
sqlserverDataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
sqlserverDataSource.setUsername("sa");
sqlserverDataSource.setPassword("1491205");
sqlserverDataSource.setUrl("jdbc:sqlserver://localhost:1433;databaseName=pgp");
context.getRegistry().bind("sqlServerDb",sqlserverDataSource);
注意:驱动类和URL