SqlSession取不到,老师同学求解
SqlSession取不到内容,报空指针错误怎么解决啊?
public class DBAccess {
public SqlSession getSqlSession() throws IOException {
// 读取配置文件
Reader reader = Resources
.getResourceAsReader("Configuration.xml");
// 构建一个SqlSessionFactory
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder()
.build(reader);
// 通过上面得到的对象开启一次回话
SqlSession sqlSession = sqlSessionFactory.openSession();
return sqlSession;
}
}
Dao层代码
public List<Message> queryMessageList(String command , String description) {
DBAccess dbAccess = new DBAccess();
SqlSession sqlSession = null ;
try {
sqlSession = dbAccess.getSqlSession();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
sqlSession.close();
}
return null ;
}
测试类
public static void main(String[] args) {
MessageDao mdDao = new MessageDao();
mdDao.queryMessageList("", "");
}
异常信息:
Exception in thread "main" java.lang.NullPointerException
at com.micro.dao.MessageDao.queryMessageList(MessageDao.java:26)
at com.test.test.main(test.java:8)
出现问题:
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
Factory并没有build出对象。。。。,这个问题怎么解决啊