yiqianyan 2017-03-28 06:09 采纳率: 100%
浏览 1165
已采纳

集合+jdbc,空指针异常

checkin_list.jsp:

 <%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page language="java"
    import="java.sql.*,java.util.*,javabean.CheckInList"%>
<html>
<head>
<title>入住记录</title>
</head>

<body>
    <table width="100%" border="1" align="center" cellpadding="3"
        cellspacing="1" bordercolor="00FFFF" style="border-collapse: collapse">
        <tr>
            <td width="30" align="center" bgcolor="CCFFFF">序号</td>
            <td bgcolor='#CCFFFF'>编号</td>
            <td bgcolor='#CCFFFF'>类型</td>
            <td bgcolor='#CCFFFF'>大小</td>
            <td bgcolor='#CCFFFF'>价格</td>
            <td bgcolor='#CCFFFF'>姓名</td>
            <td bgcolor='#CCFFFF'>身份证</td>
            <td bgcolor='#CCFFFF'>预住天数</td>
            <td bgcolor='#CCFFFF'>应付金额</td>
            <td bgcolor='#CCFFFF'>压金</td>
            <td bgcolor='#CCFFFF' width='80' align='center'>是否退房</td>
            <td width="138" align="center" bgcolor="CCFFFF">添加时间</td>
        </tr>
        <%
            String sql = "select  * from checkin";  
            CheckInList cil = new CheckInList();
            List list = cil.excuteSql(sql);
            for(int i=0;i<list.size();i++){
                CheckInList c=(CheckInList)list.get(i);
                int checkin_id = c.getCheckin_id();
                String room_number = c.getRoom_number();
                String room_type = c.getRoom_type();
                String room_size = c.getRoom_size();
                String room_price = c.getRoom_price();
                String customer_name = c.getCustomer_name();
                String customer_id_card = c.getCustomer_id_card();
                String days_to_stay = c.getDays_to_stay();
                String amount_payable = c.getAmount_payable();
                String deposit = c.getDeposit();
                String ischeckout = c.getIscheckout();
                String checkin_addedtime = c.getCheckin_addedtime();
        %>
        <tr>
            <td width="30" align="center"><%=i%></td>
            <td><%=room_number%></td>
            <td><%=room_type%></td>
            <td><%=room_size%></td>
            <td><%=room_price%></td>
            <td><%=customer_name%></td>
            <td><%=customer_id_card%></td>
            <td><%=days_to_stay%></td>
            <td><%=amount_payable%></td>
            <td><%=deposit%></td>
            <td width='80' align='center'><%=ischeckout%></td>
            <td width="138" align="center"><%=checkin_addedtime%></td>
        </tr>
        <%
            //while的括号
            }
        %>
    </table>

</body>
</html>

CheckInList.java:

package javabean;

import java.sql.*;
import java.util.*;

import db.DBUtil;

public class CheckInList {
    private int checkin_id;
    private String room_number;
    private String room_type;
    private String room_size;
    private String room_price;
    private String customer_name;
    private String customer_id_card;
    private String days_to_stay;
    private String amount_payable;
    private String deposit;
    private String ischeckout;
    private String checkin_addedtime;

    private Connection conn;
    private Statement stmt;
    private ResultSet rs;
    private List list;
    private CheckInList cil;

    public List excuteSql(String sql) {
        conn = DBUtil.getConnection();
        try {
            stmt = conn.createStatement();

            rs = stmt.executeQuery(sql);
            while (rs.next()) {
                cil=new CheckInList();
                cil.setCheckin_id( rs.getInt("checkin_id"));
                cil.setRoom_number(rs.getString("room_number"));
                cil.setRoom_type(rs.getString("room_type"));
                cil.setRoom_size(rs.getString("room_size"));
                cil.setRoom_price(rs.getString("room_price"));
                cil.setCustomer_name(rs.getString("customer_name"));
                cil.setCustomer_id_card(rs.getString("customer_id_card"));
                cil.setDays_to_stay(rs.getString("days_to_stay"));
                cil.setAmount_payable(rs.getString("amount_payable"));
                cil.setDeposit(rs.getString("deposit"));
                cil.setIscheckout(rs.getString("ischeckout"));
                cil.setCheckin_addedtime( rs.getString("checkin_addedtime"));
                list.add(cil);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }


    public int getCheckin_id() {
        return checkin_id;
    }

    public void setCheckin_id(int checkin_id) {
        this.checkin_id = checkin_id;
    }

    public String getRoom_number() {
        return room_number;
    }

    public void setRoom_number(String room_number) {
        this.room_number = room_number;
    }

    public String getRoom_type() {
        return room_type;
    }

    public void setRoom_type(String room_type) {
        this.room_type = room_type;
    }

    public String getRoom_size() {
        return room_size;
    }

    public void setRoom_size(String room_size) {
        this.room_size = room_size;
    }

    public String getRoom_price() {
        return room_price;
    }

    public void setRoom_price(String room_price) {
        this.room_price = room_price;
    }

    public String getCustomer_name() {
        return customer_name;
    }

    public void setCustomer_name(String customer_name) {
        this.customer_name = customer_name;
    }

    public String getCustomer_id_card() {
        return customer_id_card;
    }

    public void setCustomer_id_card(String customer_id_card) {
        this.customer_id_card = customer_id_card;
    }

    public String getDays_to_stay() {
        return days_to_stay;
    }

    public void setDays_to_stay(String days_to_stay) {
        this.days_to_stay = days_to_stay;
    }

    public String getAmount_payable() {
        return amount_payable;
    }

    public void setAmount_payable(String amount_payable) {
        this.amount_payable = amount_payable;
    }

    public String getDeposit() {
        return deposit;
    }

    public void setDeposit(String deposit) {
        this.deposit = deposit;
    }

    public String getIscheckout() {
        return ischeckout;
    }

    public void setIscheckout(String ischeckout) {
        this.ischeckout = ischeckout;
    }

    public String getCheckin_addedtime() {
        return checkin_addedtime;
    }

    public void setCheckin_addedtime(String checkin_addedtime) {
        this.checkin_addedtime = checkin_addedtime;
    }

}


异常信息:
严重: Servlet.service() for servlet [jsp] in context with path [/test] threw exception [An exception occurred processing JSP page /checkin_list.jsp at line 29

26: <%
27: String sql = "select * from checkin";

28: CheckInList cil = new CheckInList();
29: List list = cil.excuteSql(sql);
30: for(int i=0;i<list.size();i++){
31: CheckInList c=(CheckInList)list.get(i);
32: int checkin_id = c.getCheckin_id();

Stacktrace:] with root cause
java.lang.NullPointerException
at javabean.CheckInList.excuteSql(CheckInList.java:48)

  • 写回答

4条回答 默认 最新

  • coder_17 2017-03-28 06:33
    关注

    list给个实现类,比如arrayList

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 unity2D 关于圆心产生偏移的问题
  • ¥15 计算机微处理器与接口技术相关问题,求解答图片的这个问题,有多少个端口,端口地址和解答问题的方法和思路,不要AI作答
  • ¥15 如何根据一个截图编写对应的HTML代码
  • ¥15 谁能远程帮我装好软件,破解覆盖主程序,启动后左侧选择字典,输入单词,报酬15元,加我微信15218392686
  • ¥15 stm32标准库的PID角度环
  • ¥15 ADS已经下载好了,但是DAS下载不了,一直显示这两种情况,有什么办法吗,非常急!
  • ¥100 Excel 点击发送自动跳转outlook邮件
  • ¥15 gis中用栅格计算器或加权总和后图层不显示,值也明显不对
  • ¥15 python使用python-pptx如何给幻灯片添加只读密码。
  • ¥15 深度神经网络传递自变量损失