- 现在既不需要
也不需要Driver driver = new com.mysql.jdbc.Driver(); DriverManager.registerDriver(driver);
使用下面的自动注册,wq是数据库的名称,前面是固定的Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/wq"; Connection connection = DriverManager.getConnection(url, "root", "1234");
- 预防sql注入,使用prepareStatement;
sql注入:String url = "select * from wq where p_name = ? and p_type = ?"; PreparedStatement preparedStatement = connection.prepareStatement(url); preparedStatement.setString(1, "vivo"); preparedStatement.setInt(2, 2);
String url = "select * from wq where name = 'a' or 'a' = 'a' and password = 'a' or 'a' = 'a' ";
网友评论