-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsqlserver.java
More file actions
21 lines (20 loc) · 705 Bytes
/
sqlserver.java
File metadata and controls
21 lines (20 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.sql.*;
public class Test {
public static void main(String[] srg) {
//加载JDBC驱动
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
//连接服务器和数据库sample
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=sample";
String userName = "sa"; //默认用户名
String userPwd = "123456"; //密码
Connection dbConn;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!"); //如果连接成功 控制台输出
}
catch (Exception e) {
e.printStackTrace();
}
}
}