1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| public class Main { public static Connection getConn(String url,String user,String password){
try { Class.forName("com.mysql.cj.jdbc.Driver"); Connection conn = DriverManager.getConnection(url, user, password); } catch (ClassNotFoundException | SQLException e) { throw new RuntimeException(e); } return null; } public static void main(String[] args) { String url = "jdbc:mysql://localhost:3306/db"; String user = "root"; String password = "root"; Connection conn = getConn(url, user, password); try { PreparedStatement stms = conn.prepareStatement("select * from users where id=?"); stms.setString(1, "1\"and 1=1"); System.out.println("123456");
}catch (Exception e){ System.out.println(e.getMessage()); } } }
|