public class MybatisUtils { Private static SqlSessionFactory SqlSessionFactory;
The static {
Try { String resource="mybatis-config.xml"; InputStream inputStream=Resources.getResourceAsStream(resource); SqlSessionFactory=new the SqlSessionFactoryBuilder is (). The build (inputStream); } the catch (IOException e) { e.printStackTrace(); }
}
Public static SqlSession getSqlSession () { Return sqlSessionFactory. OpenSession ();
}
}
And then testing found
@ Test Public void testConnection () { SqlSession SqlSession=MybatisUtils. GetSqlSession (); System. The out. Println (sqlSession);
}
Though it is wrong to connect to the database password, sqlSession or can create
So I subjects misarrangement 1. Before may be sqlSession didn't shut down, read the last sqlSession 2. The IDEA to connect the database, I turn off the IDEA of database, and even the entire database services are stopped But still can create sqlSession According to my understanding, mybatis is according to mybatis - config. XML create sqlSessionFactory, again by sqlSessionFactory. OpenSession () out the sqlSession, XML is mybatis - config. Connect to the database account password is wrong sqlSessionFactory is how created
CodePudding user response:
, it's no use password and drive on
CodePudding user response:
Because getting connection don't here Is finally passed the Transaction interface to get the connection, the premise is to perform Executor of query or update method