Using a prepared statement and variable bind Order By in Java with JDBC driver

前端 未结 3 1780
情深已故
情深已故 2020-12-01 14:27

I\'m using

  1. jdbcTemplate to make JDBC connections to a mySQL DB
  2. prepared statements to protect myself as much as possible from SQL injection attacks
3条回答
  •  庸人自扰
    2020-12-01 14:55

    I would just concatenate the column name and the order to the SQL query, but only after

    1. verifying that the column name and order are valid in this context.
    2. sanitizing them to counter any attempt of SQL Injection attack.

    I feel this is efficient compared to fetching the results to the application layer and sorting them here.

提交回复
热议问题