写了一个连接数据库类,开始是这样写的:
public class OrderPizzaDB
{
    private static String dbUrl = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
    private static String dbUser = "sa";
    private static String dbPwd ="";
    
    public OrderPizzaDB() throws Exception
    {
       Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();    }
    
    
    /**
     * 获取连接
     * @return
     * @throws Exception
     */
    public static Connection getConnection() throws Exception
    {
        return DriverManager.getConnection(dbUrl,dbUser,dbPwd);
    }
会报SQLException----No suitable driver
改为了:
public class OrderPizzaDB
{
    private static String dbUrl = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
    private static String dbUser = "sa";
    private static String dbPwd ="";
    
    public OrderPizzaDB() throws Exception
    {
       
    }
    
    
    /**
     * 获取连接
     * @return
     * @throws Exception
     */
    public static Connection getConnection() throws Exception
    {
        Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
        return DriverManager.getConnection(dbUrl,dbUser,dbPwd);
    }
就不会出现错误了,这里有点不太理解。