创建连接
a、注册驱动
DriverManager.registerDriver(new com.mysql.jdbc.Driver());不建议试用
1.重复加载两次
2.强烈依赖于数据库的驱动Jar
b、加载驱动
Class.forName("com.mysql.jdbc.Driver");
与数据库建立连接
jdbc:mysql://localhost:3306/test?/useSSL=true
协议 子协议 IP:端口号 数据库 ssl返回boolen值
-------------------------------------------------------------------------------------------------
1.getConnection(String url,Properties info)
Properties info=new Properties();
info.setProperty("user", "root");
info.setProperty("password", "323915");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test? useSSL=true", info);
-------------------------------------------------------------------------------------------------
2.getConnection(String url,String user,String password)
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useSSL=true", "root", "323915");
-------------------------------------------------------------------------------------------------
a、注册驱动
DriverManager.registerDriver(new com.mysql.jdbc.Driver());不建议试用
1.重复加载两次
2.强烈依赖于数据库的驱动Jar
b、加载驱动
Class.forName("com.mysql.jdbc.Driver");
与数据库建立连接
jdbc:mysql://localhost:3306/test?/useSSL=true
协议 子协议 IP:端口号 数据库 ssl返回boolen值
-------------------------------------------------------------------------------------------------
1.getConnection(String url,Properties info)
Properties info=new Properties();
info.setProperty("user", "root");
info.setProperty("password", "323915");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test? useSSL=true", info);
-------------------------------------------------------------------------------------------------
2.getConnection(String url,String user,String password)
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useSSL=true", "root", "323915");
-------------------------------------------------------------------------------------------------