Bug #84117 includeThreadNamesAsStatementComment ignored when using prepared statement
Submitted: 8 Dec 2016 14:49 Modified: 24 Sep 18:03
Reporter: Radosław Postołowicz Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.40 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any

[8 Dec 2016 14:49] Radosław Postołowicz
Description:
Thread name as comment is not included into query when using prepared statement.

How to repeat:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ThreadNamesTest {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        try (
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/testdb?includeThreadNamesAsStatementComment=true", "user", "pass");
            PreparedStatement preparedStatement = connection.prepareStatement("select 1");
            ResultSet resultSet = preparedStatement.executeQuery()
        ) {

        }
    }
}
[13 Dec 2016 16:46] Filipe Silva
Hi Radosław,

Thank you for this bug report.

This was verified as described.
[28 Aug 2023 14:30] OCA Admin
Contribution submitted via Github - Fix for Bug#84117 PreparedStatement support includeThreadNamesAsStatementComment 
(*) Contribution by yyjun yyjun (Github cxzl25, mysql-connector-j/pull/99#issuecomment-1695748881): I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: git_patch_1475708784.txt (text/plain), 2.07 KiB.

[24 Sep 18:03] Daniel So
Posted by developer:
 
Added the following entry to the Connector//J 9.1.0 changelog: 

"PreparedStatments executed with the connection property includeThreadNamesAsStatementComment set to true did not include the name of the current thread in a comment as expected. This fix corrected the omission. Thanks to Yyjun Yyjun for contributing to this patch."