public class DBAccess {
public SqlSession getSqlSession() throws IOException {
// 通过配置文件获取数据库连接信息
Reader reader = Resources.getResourceAsReader("C:\\Users\\leon\\workspace\\mybatis_one\\config\\Configuration.xml");
// 通过配置信息构建一个SqlSessionFactory
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
// 通过sqlSessionFactory打开一个数据库会话
SqlSession sqlSession = sqlSessionFactory.openSession();
return sqlSession;
}
}
public class Inport {
public static void main(String[] args) {
UserService userService = new UserService();
List<User> users = userService.queryAllUserList();
System.out.println(users);
}
}
Exception
java.io.IOException: Could not find resource C:\Users\leon\workspace\mybatis_one\config\Configuration.xml
at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:110)
at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:97)
at org.apache.ibatis.io.Resources.getResourceAsReader(Resources.java:155)
at com.leon.db.DBAccess.getSqlSession(DBAccess.java:17)
at com.leon.dao.UserDao.queryAllUserList(UserDao.java:48)
at com.leon.service.UserService.queryAllUserList(UserService.java:21)
at com.leon.service.Inport.main(Inport.java:10)
[]
qpqpwj
相关分类