How to avoid “Security - A prepared statement is generated from a nonconstant String” FindBugs Warning

前端 未结 7 2913
灰色年华
灰色年华 2021-02-19 21:39

I am working on a project that has a piece of code like the one below:

String sql = \"SELECT MAX(\" + columnName + \") FROM \" + tableName;                
Prepa         


        
7条回答
  •  醉梦人生
    2021-02-19 22:10

    Neither String.format nor StringBuilder (or StringBuffer) helped me.

    Solution was "prepareStatement" isolation:

    private PreparedStatement prepareStatement(Connection conn, String sql) throws SQLException {
        return conn.prepareStatement(sql);
    }
    

提交回复
热议问题