<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@page language="java" import="java.io.*, java.util.*,java.sql.*"%> <jsp:useBean id="data" scope="page" class="HW.search"/> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Web Tech Homework</title> </head> <body> <table border="1"> <tr> <th></th> <th>CarID</th> <th>FirmName</th> <th>CarModel</th> <th>CarType</th> <th>ProductYear</th> <th>Km</th> <th>Color</th> <th>EngineType</th> <th>Price</th> <th>ExtraInformation</th> </tr> <% int counter = 0; ResultSet rs = data.getCarTable(); while (rs.next()) { // row by row //database colums name counter++; int t1 = rs.getInt("CarID"); // 1st col String t2 = rs.getString("FirmName");// 1st col String t3 = rs.getString("CarModel");// 1st col String t4 = rs.getString("CarType");// 1st col String t5 = rs.getString("ProductYear");// 1st col String t6 = rs.getString("Km");// 1st col String t7 = rs.getString("Color");// 1st col String t8 = rs.getString("EngineType");// 1st col String t9 = rs.getString("Price");// 1st col String t10 = rs.getString("ExtraInfomation");// 1st col %> <tr> <td><input type="radio" name="<%=counter%>"/></td> <td><%=t1%></td> <td><%=t2%></td> <td><%=t3%></td> <td><%=t4%></td> <td><%=t5%></td> <td><%=t6%></td> <td><%=t7%></td> <td><%=t8%></td> <td><%=t9%></td> <td><%=t10%></td> </tr> <% } //close while loop here %> </table> <% rs.close(); %> </body> </html>
package HW; import java.sql.*; public class database { static Connection con = null; public database() { makeConnection(); } public void makeConnection() { String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; String url = "jdbc:odbc:DB"; try { //Class.forName(driver); con = DriverManager.getConnection(url); } catch (Exception err) { System.out.println(err); } } }
package HW; import java.sql.*; public class search { public search() { new database(); } public ResultSet getCarTable() { ResultSet rs = null; try { Statement stmt = database.con.createStatement(); rs = stmt.executeQuery("SELECT * FROM CAR"); } catch (Exception err) { err.printStackTrace(); } return rs; } }
HTTP Status 500 - java.lang.NullPointerException type Exception report message java.lang.NullPointerException description The server encountered an internal error that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: java.lang.NullPointerException org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause java.lang.NullPointerException HW.search.getCarTable(search.java:16) org.apache.jsp.index_jsp._jspService(index_jsp.java:101) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.53 logs. Apache Tomcat/7.0.53
Statement stmt = database.con.createStatement();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)