在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();
}
posted @ 2015-08-17 14:09  #料  阅读(1161)  评论(0编辑  收藏  举报