1

我的代码中出现以下异常:

我经常收到这个错误。

java.lang.NullPointerException
    at com.mysql.jdbc.ResultSet.buildIndexMapping(ResultSet.java:616)
    at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:946)
    at com.mysql.jdbc.ResultSet.getString(ResultSet.java:5613)
    at com.sfmfm.database.DB_DashBoard.doGet(DB_DashBoard.java:275)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

对于这个jsp数据没有正确加载。浏览器:火狐最新

如果我在 Eclipse 中运行它,它工作正常。

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sfmfm.properties.efmfm;


@WebServlet("/DB_DashBoard")
public class DB_DashBoard extends DB_Conn {
    /**
     * 
     */
    private static final long serialVersionUID = -5639866791158510975L;
    static Statement st,st1;

    public DB_DashBoard() throws Exception {
        super();
        st=con.createStatement();
        st1=con.createStatement();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        out=response.getWriter();
        String query=request.getParameter("query");

                // create a java calendar instance
                //Calendar calendar = Calendar.getInstance();

                // get a java.util.Date from the calendar instance.
                // this date will represent the current instant, or "now".

        Date now = new Date();

        if(query != null && query.contains("~"))
        {
            System.out.println("Web Browser Request--"+query);
            /*System.out.println("Today Date" +now);        */
            String browser_req[]=query.split("~");





                        if(browser_req[0].equals("Fetch_Pending_Fee"))
                        {

                                StringBuffer AllList = new StringBuffer();

                                try {
                                   ResultSet rs=st1.executeQuery("SELECT sm.first_name, sm.last_name, " +
                                        "cs.section_name, cs.class_name, sp.balance_amount, tm.first_name as tfname,tm.last_name as tlname, " +
                                        "sm.contact_no, ft.due_date FROM teacher_master tm,student_master sm," +
                                        " student_payment sp, class_section cs, fee_type ft, student_class sc WHERE" +
                                        " sp.balance_amount!=0 AND sp.student_id = sm.student_id AND" +
                                        " sm.student_id = sc.student_id AND sc.class_id = cs.class_id AND " +
                                        "cs.class_name = ft.class_name AND tm.teacher_id = cs.teacher_id AND ft.fee_type_id=sp.payment_id AND " +
                                        "TO_DAYS(ft.due_date) < TO_DAYS(NOW())");
                                   if (rs != null)
                                    {
                                         while(rs.next())

                                     {
                                         AllList.append("<PENDING>");
                                         AllList.append("<FIRSTNAME>" + rs.getString("first_name") + "</FIRSTNAME>");
                                         AllList.append("<LASTNAME>" + rs.getString("last_name") + "</LASTNAME>");
                                         AllList.append("<CONTACT>" + rs.getString("contact_no") + "</CONTACT>");
                                         AllList.append("<BALANCE>" + rs.getString("balance_amount") + "</BALANCE>");
                                         AllList.append("<DUE>" + rs.getString("due_date") + "</DUE>");
                                         AllList.append("<SECTION>" + rs.getString("section_name") + "</SECTION>");
                                         AllList.append("<CLASS>" + rs.getString("class_name") + "</CLASS>");
                                         AllList.append("<TFNAME>" + rs.getString("tfname") + "</TFNAME>");
                                         AllList.append("<TLNAME>" + rs.getString("tlname") + "</TLNAME>");
                                         AllList.append("<SECTION>" + rs.getString("section_name") + "</SECTION>");
                                         AllList.append("</PENDING>");

                                      }

                                        response.setContentType("text/xml");
                                        response.setHeader("Cache-Control", "no-cache");
                                        response.setHeader("Access-Control-Allow-Origin", "*");
                                        response.getWriter().println("<CATALOG>" + AllList.toString() +"</CATALOG>");

                                        System.out.println("Response sent="+"<CATALOG>" + AllList.toString()+ "</CATALOG>");
                            }

                                }
                            catch (Exception e)
                            {
                            System.out.println("S: Errorhai2");
                            e.printStackTrace();
                            }



                        }
                        else if(browser_req[0].equals("alert_past_info"))
                        {

                                StringBuffer AllList = new StringBuffer();

                                try {
                                   ResultSet rs=st.executeQuery("SELECT DAY(date_time) AS aday, MONTHNAME(date_time) AS amonth,TIME(date_time) AS atime,title,category,sub_category,details FROM  post_alert ");
                                   if (rs != null)
                                    {
                                          while(rs.next())
                                     {
                                         AllList.append("<PASTALERT>");
                                         AllList.append("<ADAY>" + rs.getInt("aday") + "</ADAY>");
                                         AllList.append("<AMONTH>" + rs.getString("amonth") + "</AMONTH>");
                                         AllList.append("<ATIME>" + rs.getInt("atime") + "</ATIME>");
                                         AllList.append("<ATITLE>" + rs.getString("title") + "</ATITLE>");
                                         AllList.append("<ACATA>" + rs.getString("category") + "</ACATA>");
                                         AllList.append("<ASUB>" + rs.getString("sub_category") + "</ASUB>");
                                         AllList.append("<ADESC>" + rs.getString("details") + "</ADESC>");
                                         AllList.append("</PASTALERT>");
                                      }
                                        response.setContentType("text/xml");
                                        response.setHeader("Cache-Control", "no-cache");
                                        response.setHeader("Access-Control-Allow-Origin", "*");
                                        response.getWriter().println("<CATALOG>" + AllList.toString() +"</CATALOG>");

                                        System.out.println("Response sent="+"<CATALOG>" + AllList.toString()+ "</CATALOG>");
                            }

                                }
                            catch (Exception e)
                            {
                            System.out.println("Error On Past Alert Viewing");
                            e.printStackTrace();
                            }

                        }



        }
}


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

}

请提供清除此错误的建议。

4

1 回答 1

0

您得到的错误来自 mysql 驱动程序。Eclipse 中的类路径可能会使用与部署应用程序后使用的驱动程序版本不同的驱动程序版本。它可能解释了为什么在 Eclipse 中运行时永远不会出现此错误。

所以我建议您检查您正在使用的驱动程序版本(并可能升级您在部署应用程序时使用的驱动程序版本)。

于 2013-01-30T13:47:21.900 回答