Mybatis 中获得 connection


转:

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");


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM