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