jdbctemplate - Spring JDBC connection without dataSource -


i had read several articles on obtaining connection using spring datasource.

but in our company setup, connection object obtained through configured environment. following sample code:

 string pool = propertyfilereader.getpropertyvalue("database.properties", "development.connectionpool");      connection connection = requestutils.getconnection(pool); 

hence, after reading tutorial

i confused on using jdbctemplate using connection object above code.

i believe jdbctemplate not designed work against connection expected. workaround, if fine create separate jdbctemplate each connection created, may wrap connection in thin wrapper of datasource, , feed jdbctemplate.

i think should work haven't tried anyway...

class singleconnectiondatasource implements datasource {     private connection connection;     public singleconnectiondatasource(connection connection) {         this.connection = connection;     }      public connection getconnection() {          return this.connection;     }     public connection getconnection(string username, string password) {          return this.connection;     } }  // @ place want use jdbctemplate connection conn = blablabla;  // own way jdbctemplate jdbctemplate = new jdbctemplate(new singleconnectiondatasource(conn)); 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -