首先下载对应的JDBC驱动包,sql2008的,然后引入到项目里
通过这段代码可以获取到链接
static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
static final String URL = "jdbc:sqlserver://localhost:1433;databaseName=数据库的名字";
static final String USER = 你数据库的用户名;
static final String PWD = 密码;
public static Connection getConnection() {
Connection con = null;
try {
Class.forName(DRIVER);
con = DriverManager.getConnection(URL, USER,PWD);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}