Untitled

 avatar
unknown
plain_text
2 years ago
2.3 kB
5
Indexable
To print the SQL query generated by `jdbcTemplate.update` along with its parameters, you can add log statements before or after the update operation. Here's an example using SLF4J and Logback for logging:

```java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class YourEntityRepository {

    private final Logger logger = LoggerFactory.getLogger(YourEntityRepository.class);

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void insertRecord(YourEntity entity) {
        String sql = "INSERT INTO your_table_name " +
                     "(registered_date, last_updated_date, first_name, last_name, " +
                     "date_of_birth, nationality, is_byblos_customer, bo2_account, " +
                     "bo2_currency, bo2_reference, cif, is_active) " +
                     "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        // Log SQL query and parameters
        logger.info("Executing SQL: {} with parameters: {}", sql, entity.getRegisteredDate(), entity.getLastUpdatedDate(), entity.getFirstName(), entity.getLastName(), entity.getDateOfBirth(), entity.getNationality(), entity.getIsByblosCustomer(), entity.getBo2Account(), entity.getBo2Currency(), entity.getBo2Reference(), entity.getCif(), entity.getIsActive());

        jdbcTemplate.update(sql,
                entity.getRegisteredDate(),
                entity.getLastUpdatedDate(),
                entity.getFirstName(),
                entity.getLastName(),
                entity.getDateOfBirth(),
                entity.getNationality(),
                entity.getIsByblosCustomer(),
                entity.getBo2Account(),
                entity.getBo2Currency(),
                entity.getBo2Reference(),
                entity.getCif(),
                entity.getIsActive());
    }
}
```

In this example, we use SLF4J's Logger to log the SQL query and parameters before executing the `update` operation. Adjust the log level (e.g., `logger.info`, `logger.debug`) based on your logging preferences and environment. Ensure that you have the necessary logging dependencies in your project.
Editor is loading...
Leave a Comment