我照书上的设好环境并把驱动中那3个jar文件都安置好后连接代码如下:
package Ch4;
import java.sql.*;
public class Test {
    static {
        try{
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            System.out.println("Success loading MS SQL Server Driver...");
        }
        catch (Exception e) {
            System.out.println("Error loading MS SQL Server Driver...");
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        String strSQL = "";
    if (args.length != 0) {
      strSQL = args[0];
      System.out.println("The SQL command you want to execute is");
      System.out.println(strSQL);
    }
    else {
      System.out.println("Please input the SQL command");
      System.exit(0);
    }
    try {
      DBConnection DBCon = new DBConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=网络选课","sa","sa");
      Connection con = DBCon.makeConnection();
      DisplayResult drs1 = new DisplayResult(strSQL, con);
      drs1.show();  
    }
    catch (Exception e) {
     e.printStackTrace();
   }
  }
}运行结果如下:
Success loading MS SQL Server Driver...
Please input the SQL command