码迷,mamicode.com
首页 > 其他好文 > 详细

Mybatis 中获得 connection

时间:2019-04-23 17:12:58      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:href   tab   cti   etc   res   csdn   cep   details   code   

转:

Mybatis 中获得 connection

  1. @Autowired
  2. private SqlSession sqlSession;

 

  1. public Connection getConnection(){
  2. Connection conn = null;
  3. try {
  4. conn = sqlSession.getConfiguration().getEnvironment().getDataSource().getConnection();
  5. logger.info("===This Connection isClosed ? "+conn.isClosed());
  6. } catch (Exception e) {
  7. e.printStackTrace();
  8. }
  9. return conn;
  10. }

 

    1. String resource = "SqlMap.xml"; Reader reader = Resources.getResourceAsReader(resource);
    2. SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
    3. Connection db = sqlMap.getDataSource().getConnection();
    4. Statement st = db.createStatement();
    5. ResultSet rs = st.executeQuery("show tables");

Mybatis 中获得 connection

标签:href   tab   cti   etc   res   csdn   cep   details   code   

原文地址:https://www.cnblogs.com/libin6505/p/10757303.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!