翻页技术碰到了问题在实际的应用过程当中,现在给出源程序大家看看毛病出在那里????

boyandgirl 2001-11-14 02:22:16
<%@page language="java" import="java.sql.*"%>
<%@page contentType="text/html;charset=gb2312"%>
<%
Connection sqlCon;
Statement sqlStmt;
ResultSet sqlRst;
String strCon;
String strSql;
int intPageSize;//每页记录数
int intRowCount;//记录总数
int intPageCount;//总页数
int intPage;//当前页码
String strPage;//传替参数使用
int i;//循环变量
intPageSize=10;
strPage=request.getParameter("page");//
//以不带页码访问的时候,没有参数,此时为首页
if(strPage==null){
intPage=1;
}
else{
intPage=java.lang.Integer.parseInt(strPage);//转换字符传为整形
if(intPage<1)intPage=1;
}
//以下是加载驱动程序
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e){
System.err.println("opendb():"+e.getMessage());}

strCon="jdbc:odbc:db1";
sqlCon=DriverManager.getConnection(strCon);
sqlStmt=sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
strSql="select * from customer";
sqlRst=sqlStmt.executeQuery(strSql);

//系统指针直到最后一行
sqlRst.last();
//获得总的行数
intRowCount=sqlRst.getRow();
//计算总的叶数
intPageCount=(intRowCount+intPageSize-1)/intPageSize;
//对于大于总页数的页面,调整为最大页码
if(intPage>intPageCount)intPage=intPageCount;

%>
<HTML>
<HEAD>
<TITLE> test page </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<table border="1" width="100%" cellspacing="1" cellpadding="0" height="81">
<!--定义表头-->
<tr>
<td width="20" bgcolor="#ccffcc" height="10">name</td>
<td width="20" bgcolor="#ccffcc" height="10">cust_name</td>
<td width="20" bgcolor="#ccffcc" height="10">address</td>
</tr>
<%
if(intPageCount>0){
//移动指针导显示页的第一条记录上面
sqlRst.absolute((intPage-1)*intPageSize+1);
//显示当前的记录
i=0;
while(i<intPageSize&&!sqlRst.isAfterLast()){
%>
<tr bgcolor=#f2f2e6>
<td width="20" height="10"><%=sqlRst.getString(1)%></td>
<td width="20" height="10"><%=sqlRst.getString(2)%></td>
<td width="20" height="10"><%=sqlRst.getString(3)%></td>
</tr>
<%
//移动到下一条记录
sqlRst.next();
}
}
%>
</table>
<!--下面是定义翻页用的表单-->
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<form action="testpage.jsp" method="GET">
<td height="27" bgcolor="#99ffcc" align="right">
<%
//用于生成翻页的草连接
if(intPage!=1)
//不是第一页,生成。。。。。
{
out.println("<a href=testpage.jsp?page=1>第一页</a>");
out.println("<a href=testpage.jsp?page="+(intPage-1)+">上一页</a>");
}
if(intPage!=intPageCount)
//不是最后一页生成
{
out.println("<a href=testpage.jsp?page="+(intPage+1)+">下一页</a>");
out.println("<a href=testpage.jsp?page="+intPageCount+">最后一页</a>");
}
%> 输入页数:<input type="text" size="3" name="page">
<!--显示当前页数和总的页数-->
页数:<font color="#ff0000"><%=intPage%>/<%=intPageCount%></font>
</form>
</tr>
</table>
</BODY>
</HTML>
<%
sqlRst.close();
sqlStmt.close();
sqlCon.close();
%>
报以下错误
/cjjtlg/testpage.jsp:

Exception thrown on line '32' from page 'D:\\java\\JRun\\servers\\default\\cjjtlg\\testpage.jsp'.
java.sql.SQLException: [Microsoft][ODBC q¨ ¡h] *Ñ°pn
ðv*šØ¤q¨
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:2458)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:320)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:163)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at jrun__testpage2ejspd._jspService(jrun__testpage2ejspd.java:73)
at allaire.jrun.jsp.HttpJSPServlet.service(../jsp/HttpJSPServlet.java:39)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:228)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:196)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1416)
at allaire.jrun.session.JRunSessionService.service(../session/JRunSessionService.java:1082)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:1270)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:89)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1552)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1542)
at allaire.jrun.servlet.JvmContext.dispatch(../servlet/JvmContext.java:364)
at allaire.jrun.http.WebEndpoint.run(../http/WebEndpoint.java:115)
at allaire.jrun.ThreadPool.run(../ThreadPool.java:272)
at allaire.jrun.WorkerThread.run(../WorkerThread.java:75)


...全文
55 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
lliang2 2001-11-15
没有用户名和密码
回复
chinaillboy 2001-11-15
把这段程序存为displaymsg.jsp,那些js文件你用不着的,把它们删掉即可
回复
chinaillboy 2001-11-15
把这段程序存为displaymsg.jsp,那些js文件你用不着的,把它们删掉即可
回复
hendrix 2001-11-14
怎么浪漫不起来地这个东东……嘿嘿嘿……
偶也是用这个地说……
回复
boyandgirl 2001-11-14
我看起来比较费劲,对了,能够看看我程序 吗,还有你的那些javascript语句可以给我看看吗,有没有你写的一些资料可以给我看看吗
我邮箱是 cjjtlg@21cn.com
回复
chinaillboy 2001-11-14
你需要改的地方:

>>>>String dbUrl="jdbc:odbc:edusoft"; replace the "edusoft" as your own dsn_name;
>>>>Connection conn=DriverManager.getConnection(dbUrl,"sa",""); replace the "sa" and "" as your own username and pwd
>>>select top 120 * from guestbook order by thetime desc"); replace this as your own
回复
chinaillboy 2001-11-14
我现在调试不了,看程序太费劲。给你一个好使的吧,都用在网站了:)


<%@ page import="java.sql.*"%>
<%@ page contentType="text/html;charset=gb2312"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>留言列表</title>
<script language='javascript' src="/header.js"></script>
</head>

<body topmargin="2" leftmargin="0" bgcolor="#000000" >
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="343">
<tr>
<td width="15%" height="343" valign="top" background="../imgs/leftback.gif">
<p align="center"> </p>
<div align="center">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" align="center">
<p align="right"><a href="/support/index.jsp">
<<<返回</a></p>
</td>
</tr>
<center>
<tr>
<td width="100%" align="center"></td>
</tr>
<tr>
<td width="100%" align="center"></td>
</tr>
<tr>
<td width="100%" align="center"></td>
</tr>
</table>
</center>
</div>
</td>
<td width="85%" height="343" valign="top" background="../imgs/gstbk.jpg"><div align="center">
<br><center>
<table border="0" width="88%" cellspacing="0" cellpadding="0">
<tr>
<td width="97%" colspan="2">
 

</td>
<td width="3%">


</td>
</tr>
<tr>
<td width="97%" colspan="2">

<%
String drivername="sun.jdbc.odbc.JdbcOdbcDriver";
String dbUrl="jdbc:odbc:edusoft";
//-------------------------------------------
int intPageSize; //一页显示的记录数
int intRowCount; //记录总数
int intPageCount; //总页数
int intPage; //待显示页码
String strPage;
int i;

//设置一页显示的记录数
intPageSize = 12;

//取得待显示页码
strPage = request.getParameter("page");
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1) intPage = 1;
//-------------------------------------------------------------


try
{
Class.forName(drivername);
Connection conn=DriverManager.getConnection(dbUrl,"sa","");



Statement stm = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);

ResultSet rs=stm.executeQuery("select top 120 * from guestbook order by thetime desc");

rs.last();
intRowCount = rs.getRow();

//记算总页数
intPageCount = (intRowCount+intPageSize-1) / intPageSize;

//调整待显示的页码
if(intPage>intPageCount)
intPage = intPageCount;

out.println("<table align=center width='92%' rules=rows border=1 cellspacing=0 cellpadding=2 bordercolorlight=black bordercolordark=white>");
out.println("<tr>");
%>
<td colspan=3 bgcolor="#50A503">页数:<%=intPage%>/<%=intPageCount%> <%if (intPage<intPageCount) {%><a href="displaymsg.jsp?page=<%=intPage+1%>">下一页</a><%}%> <%if(intPage>1){%><a href="displaymsg.jsp?page=<%=intPage-1%>">上一页 <%}%></a></td><td bgcolor="#50A503">[<a href="index.jsp">发表意见</a>]</td>
<%
out.println("</tr>");
out.println("<tr>");

out.println("<td></td><td><b>主题</b></td><td><b>发言人 </b></td><td><b>发言时间</b></td></tr>");

i=0;
if(intPage==1)
rs.beforeFirst();
else
rs.absolute(intPageSize*(intPage-1));
while(i<intPageSize && rs.next())
{
String theid=rs.getString(1);
String thename=rs.getString(2);
String thetitle=rs.getString(5);
String thetime=rs.getString(7);
%>
<tr><td width='5%'><img src='imgs/circle.gif'></td><td width='50%'><a href="javascript:void(window.open('viewmsg.jsp?theid=<%=theid%>&type=msg','查看留言',' width=600, top=20, left=100, toolbar=no, menubar=no,scrollbars=auto,location=no, status=no'))"><%=thetitle%></a></td><td width='20%'><%=thename%></td><td width='25%'><%=thetime%></td></tr>
<%
i++;
}
out.println("</table>");


rs.close();
conn.close();

}
catch(Exception e)
{
}





%>


<td width="3%">


 


</td>
<tr>
<td width="2%">


</td>
<td width="95%">


 


</td>
<td width="3%">


 


</td>
</tr>
</table>
</center>
</div>
 </td>
</tr>
</table>



<script language='javascript' src="/bottom.js"></script>
</body>

</html>
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2001-11-14 02:22
社区公告
暂无公告