日期:2014-05-18  浏览次数:20780 次

百分求助,SQL语句错误,谢谢先

错误类型

java.lang.NullPointerException 空指针

不抛出异常好像到这就错 rs = db.executeQuery(PPsql);while(rs.next())

jsp源码:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<jsp:useBean id="db" scope="page" class="cn.com.util.DataBase"></jsp:useBean>
<title>添加新商品</title>
</head> 
<body bgcolor="#FFFFFF">
<table width="600" border="0" cellspacing="1" cellpadding="1" align="center"> 
<tr align="center" bgcolor="#CCCCCC"> 
<td><b>標題</b></td> 
<td><b>作者</b></td> 
<td><b>類型</b></td> 
</tr> 
<% 
String Id="";
String managerName="";
String emailAddress="";
int i; 
int ipage=2; //分頁單位 
int allpage; //總頁數 
int pages; //接受的頁碼變數 
int cpage=1; //當前頁 
int spage; //開始頁 
int allCol=0;
Vector v=null;
String PPsql,pagesql;
ResultSet rs,pagers;
  //pagesql = "SELECT COUNT(*) FROM Authors"; 
  pagesql = "SELECT COUNT(*) FROM managers"; 
//取總文章數 
//statement = conn.createStatement();
//pagers = statement.executeQuery(pagesql); 
pagers=db.executeQuery(pagesql);
while(pagers.next())
  {
  allCol = pagers.getInt(1);
  //System.out.println(allCol); 

  }
//獲得總頁面數 
allpage = (int)Math.ceil((allCol + ipage-1) / ipage); 
//判斷參數pages是否空 
if (request.getParameter("pages")==null)
  { 
pages=1; 
}
else

pages = new Integer(request.getParameter("pages")).intValue(); 
System.out.println(pages);

//判斷當前頁 
if(pages > allpage || pages == 0)
{
cpage = 1;
}
else

cpage = pages; 

//判斷起始頁 
//sql = "select Top "+ipage+" au_id,au_lname,au_fname,address,phone from authors where au_id not in (select top "+(cpage-1)*ipage+" au_id from authors order by au_id desc)order by au_id desc"; 
PPsql = "SELECT TOP "+ipage+" Id,ManagerName,EmailAddress FROM managers WHERE Id NOT IN (SELECT TOP ";
PPsql+=(cpage-1)*ipage+" Id FROM managers ORDER BY Id DESC)ORDER BY Id DESC"; 
try
{
rs = db.executeQuery(PPsql);
while(rs.next())
{
Id=rs.getString("Id");
managerName=rs.getString("ManagerName");
emailAddress=rs.getString("EmailAddress");
%> 
<tr>
  <td><%= Id %></td> 
  <td><%= managerName %></td>
  <td><%= emailAddress %></td> 
</tr> 
<%  
}
}
catch(Exception ex)