在springmvc中,获取Connection接口

ServletContext context = request.getSession().getServletContext();
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
DataSource dbSource = (DataSource) wac.getBean("dataSource"); //配置文件里的beanid
Connection con = null;
try {
con = dbSource.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}

你可能感兴趣的:(在springmvc中,获取Connection接口)