import java.sql.*;
public class SqlLink {
public static void main(String []args)
{
String userName = "TangHao";
String userPwd = "tanghao6.1";
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
//协议、主机地址、端口号、数据库名
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=MySqlTest";
try
{
Class.forName(driverName);
//指定3个参数,分别是连接地址,用户名 和密码
dbConn= DriverManager.getConnection(dbURL,userName,userPwd);
System.out.println("数据库连接成功");
}
catch ( Exception e)
{
// TODO: handle exception
e.printStackTrace();
System.out.println("连接失败");
}
}
}