![70b49d42a39fd1e23337343175d59092.png](https://i-blog.csdnimg.cn/blog_migrate/6b8f980a1e495b5e7f4011b2d75524f4.jpeg)
1、通过数据库连接池,获得查询结果集,但是无法取出数据
控制台报错:java.sql.SQLException: Before start of result set
出错代码
//获取一个连接
Connection conn = getConnection();
System.out.println("从连接池获取一个连接成功!");
PreparedStatement state = null;
ResultSet rs = null;
try {
//预编译处理
state = conn.prepareStatement("select * from user where username =? and password =?");
//填充SQL语句
state.setString(1,username);
state.setString(2,password);
rs = state.executeQuery();
//生成对象
User user = new User(rs.getString("username"), rs.getString("password")
, rs.getInt("count"));
return user;
} catch (SQLException throwables) {
throwables.printStackTrace();
} finally {
//释放资源
close(conn,state,rs);
}
原因:指针处于第一个结果集之前,取结果得先调用next()方法。
![71c92fbea4c545f88328b3121a9b8943.png](https://i-blog.csdnimg.cn/blog_migrate/7f0cdbc165ee0739a6bb96b5689abe6f.jpeg)
2、过滤器放行出错
出错代码:
//放行资源
if (requestURI.endsWith("/")||requestURI.endsWith("/index.jsp")||requestURI.endsWith("/product.jsp")||
requestURI.endsWith("/login.jsp")|| requestURI.endsWith("/error.jsp")||
requestURI.endsWith("/comment")||requestURI.endsWith("/comment.jsp")||
requestURI.endsWith("/success.jsp")||
requestURI.endsWith("/sign.jsp")||requestURI.endsWith("/notlogin.jsp")||
loginName!=null){
//调取下一个servlet或filter
filterChain.doFilter(servletRequest,servletResponse);
原因:**requestURI.endsWith("/sign.jsp")和requestURI.endsWith("/sign")**不一样,
.jsp和servlet弄混了,这种情况一般就是自己忘掉了加某个放行的条件,记得加上。
3、德鲁伊连接池获取不到连接
控制台报错:NullPointerException:The url cannot be null
网页报错:
HTTP Status 500 – Internal Server Error
Type Exception Report
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
java.lang.NullPointerException
我遇到的是配置文件出错,一旦是获取连接不成功多半都是配置文件问题,我这个就可能是手残不小心按到了一个空格。。。。。。
错误示范:
druid.properties文件
url=jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf-8
username=root
password=123456
driverClassName=com.mysql.jdbc.Driver
initialSize=5
maxActive=10
minIdle=5
maxWait=3000
你什么都看不出来
请看截图:
![bc6c6bc6ef566beae24dd196636818d2.png](https://i-blog.csdnimg.cn/blog_migrate/23088880fc3716d1082bf7d2ebcae07b.png)
删除之后天空都变晴朗了
4、过程中遇到其他问题,值得一提的是一定要注意文件所处的文件夹
我遇到了如下问题
web.xml移出WEB-INF文件夹
![abf897fb1ca700327fab44ba18a09774.png](https://i-blog.csdnimg.cn/blog_migrate/8bb0096268cba04924619fbf60b37c6d.png)
lib文件夹目录错误,创建多留个心眼,如果还是有一直导包错误问题的可以参考如下修改过程
![3b69b17d332b6903887e2879407fdbcb.png](https://i-blog.csdnimg.cn/blog_migrate/7a2d0011c0e0b1fc8ddb879dc57ab487.jpeg)
1、选择这个模式,就是将本地文件推送到tomcat下进行部署,
2、这个是推送到tomcat下文件的路径形式,web项目必须有WEB-INF文件夹,文件夹下面需要有class文件夹和lib文件,分别放编译后的class文件,和依赖的jar包
3、这个地方就是idea发现了你的项目是一个web项目,可以被引进来的项目
所以在部署的时候,先选择1,在选择3,最后看2的结构是不是符合要求
感谢你看到这里,我是程序员麦冬,一个java开发从业者,深耕行业六年了,每天都会分享java相关技术文章或行业资讯
欢迎大家关注和转发文章,后期还有福利赠送!