1

I'm using Spring JDBC + C3P0. I want to set the 'sql_mode' variable to empty string ''.

First I tried to set it in JDBC url:

DataSource dataSource = new DriverManagerDataSource(
    "jdbc:mysql://127.0.0.1/test?sessionVariables=sql_mode=''",
    "root", "password");

But it's not working.

So I'm wondering whether there's a way to execute some statements right after the connection is acquired, such as "SET sql_mode=''".

Thanks.

4

1 回答 1

2

您可以ConnectionCustomizer使用 C3P0 实现:http ://www.mchange.com/projects/c3p0/#connection_customizers

public class MyConnectionCustomizer extends AbstractConnectionCustomizer {

  public void onCheckOut( Connection c, String parentDataSourceIdentityToken ) { 
    //Run your statements here 
  }
{
于 2013-11-08T02:07:01.983 回答