jdbc连接数据库的模式
jdbc连接数据库的方式
在不使用框架的情况下,直接使用jdbc连接数据库的方式
方式一: Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "test");
方式二:
Properties props = new Properties();
props.put("user", "root");//key看数据库的规定
props.put("password", "root");
props.put("useUnicode", "true");
<!--WizRtf2Html Charset=0 -->props.put("characterEncoding", "utf8");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", props);
方式三:
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=root");