I am using spring jdbc. How can I get the current Connection object for an Oracle database? I'm using connection pooling with JBOSS WIldfly server. I am getting the connection url In my DaoImp by using the bellow code.
Connection con;
try {
con = getJdbcTemplate().getDataSource().getConnection();
dataSource.getConnection().getMetaData().getURL();
connectionUrl = con.getMetaData().getURL();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
If I write the same code in the setJdbcTemplate method then I am not getting connections over there.There error as follows
No managed connections available within configured blocking timeout (0 [ms]) my setJdbcTemplate method as follwos
public void setDataSource(DataSource dataSource){
this.dataSource = dataSource;
setJdbcTemplate(new JdbcTemplate(this.dataSource));
setNamedParamdbcTemplate(new NamedParameterJdbcTemplate(this.dataSource));
if(connectionUrl==null){
Connection con;
try {
con = getJdbcTemplate().getDataSource().getConnection();
connectionUrl = con.getMetaData().getURL();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Try increase blocking timeout in ds.xml file. see configure data source in JBOSS
blocking-timeout-millis : This element specifies the maximum time in milliseconds to block while waiting for a connection before throwing an exception. Note that this blocks only while waiting for a permit for a connection, and will never throw an exception if creating a new connection takes an inordinately long time. The default is 5000.
- the length of time to wait for a connection to become available when all the connections are checked out (default 5000 == 5 seconds, from 3.2.4 it is 30000 == 30 seconds)
<blocking-timeout-millis>5000</blocking-timeout-millis>