5、选择一个项目右键单击目录窗口中的Test, 选择Build Path --> Configure Build Path..., 添加扩展jar文件,即把sqljdbc.jar添加到其中
import java.sql.*;
public class Test {
public static void main(String[] srg) {
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=information";
String userName = "sa";
String userPwd = "123";
Connection dbConn;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!");
} catch (Exception e) {
e.printStackTrace();
}
}
}