Hi Saugata,
This might work, or you might be able to set something in your DataSource configuration. The following class extends DelegatingDataSource. You simply have to inject your current DataSource, and then every connection obtained on the target DataSource will be configured appropriately.
Code:
package org.spring.forum;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import org.springframework.jdbc.datasource.DelegatingDataSource;
public class PostProcessingDataSource extends DelegatingDataSource {
public static final String TEMPORARY_OPTION_CONN_AUTH =
"SET TEMPORARY OPTION CONN_AUTH='Company=MicroView;Application=MyDB;Sign key=1E042938-AD90-4008-B213-as0CED2FF4DD'";
@Override
public Connection getConnection() throws SQLException {
Connection connection = super.getConnection();
postProcessConnection(connection);
return connection;
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
Connection connection = super.getConnection(username, password);
postProcessConnection(connection);
return connection;
}
/**
* Post-process using the given connection.
*
* @param connection the connection to use for post-processing.
* @throws SQLException
*/
protected void postProcessConnection(Connection connection) throws SQLException {
Statement statement = connection.createStatement();
statement.execute(TEMPORARY_OPTION_CONN_AUTH);
}
}