Although the executeUpdate method itself may be thread safe, prepared statements are not intended to be used simultaneously. This is due to the fact that each instance saves your parameters until executeUpdate prompts it to send the parameters to MySQL. Moreover, since transactions are managed through Connection objects, sharing connections at the same time without synchronization can lead to unwanted commit / rollback behavior.
To make inserts from multiple threads at the same time, each thread must use its own Connection and make its own PreparedStatement . Using multiple prepared statements simultaneously in the same database is thread safe because concurrency is managed by the RDBMS.
dasblinkenlight
source share