2013-02-20 37 views
0

我發佈我的代碼,其中我得到java.lang.NullPointerException異常。獲取異常:我的JSP頁面上的java.lang.NullPointerException異常

<%@ page contentType="text/html;charset=UTF-8" %> 
<%@ page errorPage="myError.jsp?from=customers.jsp" %> 
<%@ page import="java.sql.*" %> 
<html> 
<head> 
<title>Insurance Quoting System</title> 
</head> 
<body> 
<basefont face="Arial"> 
<!-- JSP Declarations --> 
<%! ResultSet rs = null; %> 

<!-- JSP Scriptlet --> 
<% 
try { 
Class.forName("com.mysql.mysql.Driver"); 
Connection db = DriverManager.getConnection("jdbc:mysql://localhost:3306/quoting","root","root"); 
Statement s = db.createStatement(); 
rs = s.executeQuery("select * from customer"); 
} 
catch (Exception e) { 
// For now, just report the error to the system log 
System.out.println(e.toString()); 
} 
%> 
<!-- Template text --> 
<table width="550" border="0" align="center"> 
<tr> 
<td bgcolor="#006633"> 
<div align="center"> 
<font size="6" color="#FFFFFF"> 
<b>Insurance Quoting System</b> 
</font> 
</div> 
</td> 
</tr> 
<tr> 
<td> 
<p>&nbsp;</p> 
<p>&nbsp;</p> 
<p align="center"><b>Customers</b></p> 
<table width="290" border="0" align="center"> 
<% 
try { 
while (rs.next()) { 
%> 
<!-- JSP Expressions used within template text --> 
<tr> 
<td width="20"><%= rs.getInt(1) %></td> 
<td width="70"><%= rs.getString(2) %></td> 
<td width="70"><%= rs.getString(3) %></td> 
<td width="40"> 
<a href="custMaint.jsp?id=<%= rs.getString(1) %>&action=edit"> 
edit 
</a> 
</td> 
<td width="40"> 
<a href="custMaint.jsp?id=<%= rs.getString(1) %>&action=delete"> 
delete 
</a> 
</td> 
<td width="40"> 
<a href="custMaint.jsp?id=<%= rs.getString(1) %>&action=newQuote"> 

new quote 
</a> 
</td> 
</tr> 
<% 
} 
} 
catch (SQLException e) { 
// For now, just report the error to the system log 
System.out.println(e.toString()); 
} 
%> 
</table> 
</td> 
</tr> 
<tr> 
<td> 
<p>&nbsp;</p> 
<p align="center"><a href="custMaint.jsp?action=add">New Customer</a></p> 
</td> 
</tr> 
</table> 
</body> 
</html> 

我想提出一個JSP頁面其給我的jsp頁面上的一些錯誤java.lang.NullPonterException請告訴我答,如果任何一個有。

+1

堆棧跟蹤請謝謝。 – Woot4Moo 2013-02-20 15:39:06

+0

只需調試它,你會發現問題在哪裏。 – Slim 2013-02-20 15:47:58

回答

0

我能想到的唯一的事情是造成這是你趕上你的第一個try-catch塊中的異常,然後嘗試使用ResultSet因爲如果它被初始化,但它仍然是零,那麼你得到NPE 。檢查數據庫操作是否正常工作。

相關問題