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条)

报告相同问题?

悬赏问题

  • ¥80 构建降雨和积水的预测模型
  • ¥15 #Qt Transform setTransform()在鼠标拖动移动视角是一致在原地不动,无法变换视角(细微观察似乎视图有在原地抖动),无法变换视角(细微观察似乎视图有在原地抖动)
  • ¥50 如何利用无人机拍摄的数码照片测量鸟卵的长短径
  • ¥100 github贡献者给与奖励
  • ¥15 使用DS18B20+ESP8266获取温度数据返回-127.00
  • ¥15 odbc代码新增sqlserver数据源
  • ¥15 求一个USB指纹识别的驱动
  • ¥15 wps中工作表与工作表之间怎么汇总信息?
  • ¥50 请教Windows server 2012 R2的DCOM配置问题
  • ¥15 adasis v3中LaneConnectivity