I am getting error at this point of code
org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [jsp] in context with path [/Work] threw exception [An exception occurred processing JSP page /Display.jsp at line 49 46:<td> 47: <% 48: String sql="select * from Patient "; 49: pstmt=con.prepareStatement(sql); 50: rs=pstmt.executeQuery(); 51: while(rs.next()){ 52: %> Stacktrace:] with root cause java.lang.NullPointerException
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"""> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <%@page import="java.sql.DriverManager"%> <%@page import="java.sql.ResultSet"%> <%@page import="java.sql.PreparedStatement"%> <%@page import="java.sql.Connection"%> <%@page import="com.connection.*"%> <body> <%! Connection con=null; PreparedStatement pstmt=null; ResultSet rs=null; public void init() { try{ Connection con = ConnectionImplementation.wantConnection(); // Statement stmt= con.createStatement(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } %> <table> <tr> <td> <select name="PERSON_TYPE"> <option value="">SELECT</option> <option value="Doctor">Doctor</option> <option value="Nurse">Nurse</option> <option value="Patient">Patient</option> </select> </td> </tr> <tr> <td> <% String sql="select * from Patient "; pstmt=con.prepareStatement(sql); rs=pstmt.executeQuery(); while(rs.next()){ %> <tr><td> <%= rs.getInt(1)%></td> <td><%= rs.getString(2) %></td> <td><%= rs.getString(3) %></td> <td><%= rs.getInt(4) %></td> <td><%= rs.getString(5) %></td> <td><%= rs.getString(6) %></td> <td><%= rs.getString(7) %></td></tr> <% } %> </table> </body> </html> 11 Answer
Your member-variable con is never assigned a value thus null
Inside your init() method you declare a local variable con - so the member variable Connection con never changes from null to anything else.