Ideas and Code

mercoledì 13 gennaio 2010

Spring Jdbc and no transaction

You don't need transaction? Are you using Spring Jdbc (SimpleJdbcTemplate)?
If you enable profileSQL in the jdbc connection url you will notice that all your queries are sorrounded by other 2 queries:

1. SET autocommit=1

2. YOUR QUERY

3. SET autocommit=1

You don't need 1 and 3 with you are not working with transaction. They are very fast to execute but they require network communication with your DB (and you don't want that!)

You can fix that adding to your connection URL:

elideSetAutoCommits=true
useLocalSessionState=true

in my case:

jdbc:mysql://localhost:3306/myDb?connectTimeout=4000&autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&profileSql=false&elideSetAutoCommits=true&useLocalSessionState=true

In my case I'm working on Mysql ISAM tables.


Similarly, I had an annoying SHOW WARNINGS query after every query. It went away when I upgraded Spring from 2.5.4 to 2.5.6
I'm using mysql connector for Java 5.1.10

Nessun commento:

Posta un commento