I am developing a batch using Spring. To perform the query I use JdbcTemplate.
In my specific case JdbcTemplate is provided to the DAO class extending the Spring JdbcDaoSupport class, so I have the following DAO:
@Service
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public class PucManagerColl extends JdbcDaoSupport {
private static Logger log = Logger.getLogger(PucManagerProd.class);
public PucManagerColl() {
System.out.println("Costruzione PucManager");
}
@Autowired
public PucManagerColl(@Qualifier("dataSourcePUCColl") DataSource dataSource) {
setDataSource(dataSource);
}
...............................................................
...............................................................
public void insertTirConsolidatoPolizza(TassoRendimentoInterno tri) {
log.debug("PucManagerColl.insertTirConsolidatoPolizza()");
String sql = "INSERT INTO TirConsolidatoPolizza "
+ "("
+ "Polizzaid, "
+ "PercentualeRendimentoDaInizioGestione, "
+ "PercentualeRendimentoDaInizioAnno, "
+ "PercentualeRendimentoDaInizioTrimestre, "
+ "ControvaloreFinaleBF, "
+ "DataRiferimentoNav"
+ ") "
+ "VALUES (?, ?, ?, ?, ?, ?, ?)";
this.getJdbcTemplate().update(sql,
new Object[] { tri.getPolizzaID(),
tri.getPercRendimentoInizioSottoscrizione(),
tri.getPercRendimentoInizioAnno(),
tri.getPercRendimentoInizioTrimestre(),
tri.getControvaloreQuote(),
tri.getDataRiferimentoNavPUC()});
log.debug("TERMINATO: PucManagerColl.insertTirConsolidatoPolizza()");
}
}
As you can see this class extends Spring class JdbcDaoSupport and the datasource is injected into the constructor.
The problem is that the insertTirConsolidatoPolizza() method can't insert the record into the TirConsolidatoPolizza table. I obtain no error and no excption. Why? Do you notice some problem in my query?
So I want debug the query genrated by JdbcTemplate and try to perform it manually into the database prompt but I can't see it.
Reading this post: Seeing the underlying SQL in the Spring JdbcTemplate?
and the official doumentation: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jdbc.html
it seems to me that I can configure JdbcTemplate to log the query in debug mode or something like it.
In the other post show this XML snippet to do it:
<category name="org.springframework.jdbc.core.JdbcTemplate">
<priority value="debug" />
</category>
but I don't know exactly where I hae to put it.
This is my databaseConfiguration.xml that contains the informations for the DB connection (I import this file into the main configuration file applicationContext.xml):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<tx:annotation-driven transaction-manager="tjtJTransactionManager" />
<!-- DB CONNECTIONS: -->
<bean id="tjtJTransactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
scope="singleton">
<property name="dataSource" ref="dataSourcePUC" />
</bean>
<!-- PROFILO DI PRODUZIONE -->
<beans profile="PROD">
<bean id="dataSourcePUC" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver" />
<property name="url" value="jdbc:jtds:sqlserver://XXX.myCompany.YYYY.it:1433/DB_1" />
<property name="username" value="username" />
<property name="password" value="pswd" />
</bean>
</beans>
<!-- PROFILO DI COLLAUDO -->
<beans profile="COLL">
<bean id="dataSourcePUC" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver" />
<property name="url" value="jdbc:jtds:sqlserver://XXXX.MYCOMPANY.YYYY.it:1433/DB_2" />
<property name="username" value="username" />
<property name="password" value="pswd" />
</bean>
</beans>
</beans>
How can I configure the query logging to see the performed query in my stacktrace?