Mybatis 中获得 connection

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;
}  


public Connection getConnection() {
    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");
}

你可能感兴趣的:(Connection)