数据库表没有显示在jsp webapp表上

编程入门 行业动态 更新时间:2024-10-28 15:22:29
本文介绍了数据库表没有显示在jsp webapp表上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将表格内容从ms访问表导入到jsp网页表中,但是我在第31行仍然收到错误,虽然我的代码很好,有人可以详细说明我的错误吗? 继承人jsp代码:

I am trying to import table contents from a ms access table to a jsp web page table , however I keep getting an error on line 31 although my code is fine, can someone elaborate me on whats wrong here? heres the jsp code :

<%@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>

用于建立访问连接的我的Java类:

My Java Class For Establishing Access Connection :

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); } } }

我的Java类获取表内容:

My Java Class For Getting Table Contents :

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; } }

浏览器错误:

ERROR BY THE BROWSER :

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

推荐答案

连接对象变为空。 Connection object getting null. Statement stmt = database.con.createStatement();

检查makeConnection()方法是否可以实际上返回一个对象。

Check makeConnection() method whether it actually return an object or else.

更多推荐

数据库表没有显示在jsp webapp表上

本文发布于:2023-10-22 08:50:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1517032.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表上   数据库   jsp   webapp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!