在连接数据库之前,需要导入相关的驱动包
1.这是连接mysql
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://127.0.0.1:3306/android";
String name="root";
String pass="";
Class.forName(driver);
Connection conn= DriverManager.getConnection(url,name,pass);
2.这是连接SqlServer
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;databaseName=yq", "sa","123");