Class.forName方法,此方法含义是:加载参数指定的类,并且初始化它。
// TODO Auto-generated method stub //声明connection 对象 Connection con; //驱动程序名 String driver = "com.mysql.jdbc.Driver"; //URL指向要访问的数据库名 String url = "jdbc:mysql://localhost:3306/sqltestdb"; String user = "root"; String password = "123456"; try { //加载驱动程序 Class.forName((driver)); //1 .getConnection()方法连接MYSQL数据库; con = DriverManager.getConnection(url,user,password);