Java HTTP状态500错误。日食+;Tomcat+;MS SQL 2005

Java HTTP状态500错误。日食+;Tomcat+;MS SQL 2005,java,sql-server-2005,jsp,Java,Sql Server 2005,Jsp,我正在尝试这段代码,以便了解如何将MS SQL 2005连接到Eclipse和Tomcat 7作为我的服务器。我刚刚开始制作java web应用程序,请耐心听我说。在下面的错误中,如何跟踪错误的原因?该项目有2个jsp和3个类文件index.jsp,result.jsp,SQLConnection.java,Items.java和ItemController.java java.lang.NullPointerException connection.SQLConnection.execSele

我正在尝试这段代码,以便了解如何将MS SQL 2005连接到Eclipse和Tomcat 7作为我的服务器。我刚刚开始制作java web应用程序,请耐心听我说。在下面的错误中,如何跟踪错误的原因?该项目有2个jsp和3个类文件
index.jsp
result.jsp
SQLConnection.java
Items.java
ItemController.java

java.lang.NullPointerException
connection.SQLConnection.execSelectQuery(SQLConnection.java:35)
错误如下所示,

type Exception report

message 

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:722)


root cause 

java.lang.NullPointerException
connection.SQLConnection.execSelectQuery(SQLConnection.java:35)
model.Item.lastItems(Item.java:10)
org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
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:722)
SQLConnection.java和index.jsp的代码如下:

SQLConnection.java

    package connection;
    import java.sql.*;
    public class SQLConnection {
    protected Connection con=null;
    protected ResultSet rs=null;

    public SQLConnection(String address)
    {
        try
    {
    String conString = "jdbc:sqlserver://localhost:1433;databaseName=Chingdb;    integratedSecurity=true;";
con = DriverManager.getConnection(conString);
}catch(SQLException sqlError){
//ERROR MANAGEMENT HERE
}
}
public boolean execQuery(String sql)
{
boolean result = false;
try
{
Statement stmt = con.createStatement();
stmt.execute(sql);
result = true;
}catch(SQLException sqlError){
//ERROR MANAGEMENT HERE
result = false;
}
return result;
}
public void execSelectQuery(String sql)
{
try
{
Statement stmt = con.createStatement();
this.rs = stmt.executeQuery(sql);
}catch(SQLException sqlError){
//ERROR MANAGEMENT HERE
}
}
public void disconnect()
{
try
{
con.close();
}catch(SQLException sqlError){
//ERROR MANAGEMENT HERE
}

}
}
index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org    /TR/html4/loose.dtd">
<%@page import="model.Item"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Todo-List App</title>
</head>
<body>
<h2>Add a new item</h2>
<form action="addItem" method="post">
<table>
<tr>
<td><input type="text" value="I have to..." onClick="this.value('')" name="todo"/></td>
<td><input type="submit" value="Send" name="send"/> </td>
</tr>
</table>
</form>
<h2>Todo-List</h2>
<%
Item item = new Item();
String[] lastest = item.lastItems();
for(int i=0;i<lastest.length;i++)
{%>
<%=lastest[i] %> <br>
<%}item.disconnect();
%>
</body>
</html>

待办事项列表应用程序
添加新项目
待办事项清单

错误堆栈跟踪表明您在
SQLConnection.java
execSelectQuery
方法中获得了
NullPointerException
,并且当您从
Item.java
调用此方法时,获得了此异常

java.lang.NullPointerException
connection.SQLConnection.execSelectQuery(SQLConnection.java:35)
model.Item.lastItems(Item.java:10)
中的
Item.java
处放置一个调试点,然后 语句stmt=con.createStatement()


我怀疑您的
连接可能为空。

在此处添加一些相关代码:)谢谢您的回复。我已经在我的问题上添加了SQLConnection.java和index.jsp的代码。希望你能帮助我^_^@Ching29:试着调试代码,检查你的连接是否为空