jdbc连接Sql Server 2008
下载驱动包
1
https://yunpan.cn/cSgGFjDdLW9Qz 访问密码 `bc5c`
数据库连接信息
driverClass=com.microsoft.jdbc.sqlserver.SQLServerDriver
url=jdbc:microsoft:sqlserver://数据库连接ip地址
:1433;DatabaseName=数据库名称
user=sa
password=数据库访问密码
java代码
1
2
3
4
5
6
7
8
9
10
11
12
13public static void main(String[] args) throws ClassNotFoundException {
String driverClass = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
String username = "sa";
String password = "password";
Class.forName(driverClass);
try {
Connection connection = DriverManager.getConnection(url, username, password);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}