Is JDBC secure?

前端 未结 6 982
说谎
说谎 2020-12-10 09:27

I am new to JDBC, and the new project require me to use JDBC. What I want to know is,

is the JDBC secure?

How to prevent \"Mysql Injection\"-like problem?<

6条回答
  •  天命终不由人
    2020-12-10 09:53

    Use prepared statements. For a hypothetical login you might use this, for example:

    PreparedStatement stmt = conn.prepareStatement("SELECT * FROM member WHERE member_username = ? AND member_password = ?");
    stmt.setString(1, username);
    stmt.setString(2, password);
    stmt.execute();
    
    ResultSet rs = stmt.getResultSet();
    // ...
    

    This will completely shield you from SQL Injection vulnerabilities.

提交回复
热议问题