Home > Back-end >  MyBatis sqlsession problems
MyBatis sqlsession problems

Time:02-03

This is I made of tool
 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

CodePudding user response:

refer to the second floor a1767028198 response:
because getting connection don't here
Is finally passed the Transaction interface to get the connection, the premise is to perform the Executor of the query or update method

That I think doing the sqlSession sqlSession is to obtain a connection is written in and I profile password is wrong arguably not even didn't even sqlSession should also create don't come out

CodePudding user response:

reference hasn't bald head, 4/f, I can still learn response:
Quote: refer to the second floor a1767028198 response:
because getting connection don't here
Is finally passed the Transaction interface to get the connection, the premise is to perform the Executor of the query or update method

That I think doing the sqlSession sqlSession is to obtain a connection is written in and I profile password is wrong arguably not even are not even on the sqlSession should also create out
brother estimate what Transaction and Executor, it's not particularly the DataSource that clear, so it is not necessary to know so much!
As long as you know, mybatis data, query and modify the table to the sqlsession processing, but this does not mean that the underlying library is he directly related operations

CodePudding user response:

reference 5 floor a1767028198 reply:
Quote: reference hasn't bald head, 4/f, I can still learn response:
Quote: refer to the second floor a1767028198 response:
because getting connection don't here
Is finally passed the Transaction interface to get the connection, the premise is to perform the Executor of the query or update method

That I think doing the sqlSession sqlSession is to obtain a connection is written in and I profile password is wrong arguably not even are not even on the sqlSession should also create out
brother estimate what Transaction and Executor, it's not particularly the DataSource that clear, so it is not necessary to know so much!
As long as you know, mybatis data, query and modify the table to the sqlsession processing, but this does not mean that the underlying library is he directly related operations

Just learned SSM grows a new framework to reconstruct project results before many pit who did not fine thank you bosses
  • Related