Mybatis 中获得 connection
转:
Mybatis 中获得 connection
2012年07月30日 19:02:21 dqsweet 阅读数:13861- @Autowired
- private SqlSession sqlSession;
- public Connection getConnection(){
- Connection conn = null;
- try {
- conn = sqlSession.getConfiguration().getEnvironment().getDataSource().getConnection();
- logger.info( "===This Connection isClosed ? "+conn.isClosed());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return conn;
- }
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
- String resource = "SqlMap.xml"; Reader reader = Resources.getResourceAsReader(resource);
- SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
- Connection db = sqlMap.getDataSource().getConnection();
- Statement st = db.createStatement();
- ResultSet rs = st.executeQuery( "show tables");

更多精彩