当前位置: 技术问答>java相关
关于JSP分页显示。求救,大家帮帮我。
来源: 互联网 发布时间:2015-04-28
本文导语: 我根据书上的例子编了一个分页显示的javaBean,代码如下: package popeyelin; import java.sql.*; import java.lang.*; import java.io.*; import javax.servlet.http.*; import javax.servlet.*; public class messageList { int page; int count; public ...
我根据书上的例子编了一个分页显示的javaBean,代码如下:
package popeyelin;
import java.sql.*;
import java.lang.*;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class messageList
{
int page;
int count;
public void setPage(int page)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println("no");
}
this.page=page;
}
public void Display(HttpServletResponse response)
{
try
{
response.setContentType("text/html;GBK");
PrintWriter out=response.getWriter();
Connection con=DriverManager.getConnection("jdbc:odbc:JSP","huang","782600");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select count(*) from messagebook");
rs.next();
this.count=rs.getInt(1);
int first=count-(page-1)*10;
int last=count-page*10;
PreparedStatement pstmt=con.prepareStatement("select * from messagebook where uid>=? and uid");
out.print(rs.getString("email"));
out.print("");
out.print("
来自:"+rs.getString("ip")+"留言于"+rs.getString("exactpost"));
out.print("
");
out.print("他说:
");
out.print(rs.getString("content"));
out.print("");
out.print("");
}
rs.close();
}
catch(Exception e)
{
System.out.print(e.toString());
}
}
public boolean hasNext()
{
if(count>page*10) return true;
else return false;
}
}
数据库的结构为
Create bable messagebook{
uid int not null primary key,
name varchar(20),
ip varchar(20),
email varchar(50),
exactpost varchar(20),
content text
}
但运行结果显示为javax.servlet.ServletException: [Microsoft][ODBC SQL Server Driver]无效的描述符索引
请帮我看一看,谢谢!
package popeyelin;
import java.sql.*;
import java.lang.*;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class messageList
{
int page;
int count;
public void setPage(int page)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println("no");
}
this.page=page;
}
public void Display(HttpServletResponse response)
{
try
{
response.setContentType("text/html;GBK");
PrintWriter out=response.getWriter();
Connection con=DriverManager.getConnection("jdbc:odbc:JSP","huang","782600");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select count(*) from messagebook");
rs.next();
this.count=rs.getInt(1);
int first=count-(page-1)*10;
int last=count-page*10;
PreparedStatement pstmt=con.prepareStatement("select * from messagebook where uid>=? and uid");
out.print(rs.getString("email"));
out.print("");
out.print("
来自:"+rs.getString("ip")+"留言于"+rs.getString("exactpost"));
out.print("
");
out.print("他说:
");
out.print(rs.getString("content"));
out.print("");
out.print("");
}
rs.close();
}
catch(Exception e)
{
System.out.print(e.toString());
}
}
public boolean hasNext()
{
if(count>page*10) return true;
else return false;
}
}
数据库的结构为
Create bable messagebook{
uid int not null primary key,
name varchar(20),
ip varchar(20),
email varchar(50),
exactpost varchar(20),
content text
}
但运行结果显示为javax.servlet.ServletException: [Microsoft][ODBC SQL Server Driver]无效的描述符索引
请帮我看一看,谢谢!
|
数据库结构为: name、IP、email。。。
输出顺序为:name、email、IP
JDBC-ODBC桥连接数据库不支持这样读取数据。应该:
rs.getString("name"),然后rs.getString("ip")=>rs.getString("email")
输出顺序为:name、email、IP
JDBC-ODBC桥连接数据库不支持这样读取数据。应该:
rs.getString("name"),然后rs.getString("ip")=>rs.getString("email")