MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » 百分求助,SQL语句异常,多谢先

百分求助,SQL语句异常,多谢先

www.MyException.Cn  网友分享于:2013-12-12  浏览:26次
百分求助,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)
{
out.print(ex.toString());
}
%>
<tr bgcolor="#CCCCCC"> 
<td colspan="3" align="right" valign="middle">共 <%= allCol %>條記錄 共 <%= allpage %>頁 <% if (cpage>1) { %><a href="manager.jsp?pages=<%= cpage-1 %>"></a><% } if (cpage<allpage) { %><a href="manager.jsp?pages=<%= cpage+1 %>"></a><% } %> / <% for (i=1;i<=allpage;i++) { if (i != pages) {%><a href="manager.jsp?pages=<%= i %>"><%= i %></a>&nbsp;<% }} %></td> 

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有