I got NullPointerException when I tried to run this func in JSP page:
public ArrayList<Shortnews> getListNews() {
Connection cons = DBconnect.getConnecttion();
ArrayList<Shortnews> list = new ArrayList<>();
try {
CallableStatement statement = cons.prepareCall("{call spshnews_select_6news}");
ResultSet rs = statement.executeQuery();
while (rs.next()) {
Shortnews shnew = new Shortnews();
shnew.setShortnewsID(rs.getInt("shortnewsID"));
shnew.setShortnewsTitle(rs.getString("shortnewsTitle"));
shnew.setShortnewsHead(rs.getString("shortnewsHead"));
shnew.setShortnewsImg(rs.getString("shortnewsImg"));
shnew.setAuthorID(rs.getLong("authorID"));
shnew.setPublishedTime(rs.getTimestamp("publishedTime"));
shnew.setShortnewURL(rs.getString("shortnewURL"));
list.add(shnew);
}
cons.close();
} catch (NullPointerException|SQLException e) {
e.printStackTrace();
}
return list;
}
This exception only occurs when I call this function in JSP file. But I had run my procedure and function in DAO.java file successfully. Is there anything unusual, please? THis is the output:
java.lang.NullPointerException
com.bgfarm.dao.ShortnewsDAO.getList6News(ShortnewsDAO.java:54)
org.apache.jsp.index_jsp._jspService(index_jsp.java:164)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
NPE happens as soon as it runs to ResultSet rs = statement.executeQuery();
and fall down catch
I really don't know how it does.Thanks!