Preventing SQL injection without prepared statements (JDBC)

前端 未结 6 1473
情话喂你
情话喂你 2020-12-19 16:51

I have a database log appender that inserts a variable number of log lines into the database every once in a while.

I\'d like to create an SQL statement in a way tha

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-19 17:28

    what's wrong with using a regular prepared statement e.g. in the following pseudocode:

    DatabaseConnection connection;
    PreparedStatement insertStatement = ...;
    
        ...
    
    connection.beginTransaction();
    for (Item item : items)
    {
       insertStatement.setParameter(1, item);
       insertStatement.execute();
    }
    connection.commitTransaction();
    

    A smart database implementation will batch up several inserts into one communications exchange w/ the database server.

提交回复
热议问题