我正在使用spring jdbc。如何获取Oracle数据库的当前Connection对象?我正在使用JBOSS WIldfly服务器连接池。我通过使用下面的代码获取连接URL在我的DaoImp中。我如何在spring中获取当前连接url JDBC
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();
}
如果我写在setJdbcTemplate方法相同的代码然后我没有得到过错误那儿,那儿的连接如下
配置阻塞的超时时间内没有可用的管理的连接(0 [毫秒] ) 我setJdbcTemplate方法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();
}
}
}
https://meta.stackoverflow.com/q/352023/4751173 – Glorfindel