总是报错:Result set type is TYPE_FORWARD_ONLY
在JSP分页设计时,总是报错,上网查了说将result的type改了,Statement stmt=connect.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);但还是报错
将代码贴出,请高手指教~~~~
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="java.sql.*"%>
<%
Connection con = null ;
Statement stmt = null ;
ResultSet rs = null ;
String url = "jdbc:odbc:cy";
String user = "sa";
String psw = "123";
String sql = "use cy select * from news";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//注册驱动
con = DriverManager.getConnection(url,user,psw);//得到连接
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
} catch (Exception ex) {
ex.printStackTrace();
}
try{
rs = stmt.executeQuery(sql);//执行查询
} catch (Exception ex) {
rs.getType();
ex.printStackTrace();
}
int i = 0;
int intPageSize = 3;//每一页显示的记录数
int intRowCount = 0;//记录总数
int intPageCount;//总页数
int intPage = 0;//待显示页码
String strPage = null;
strPage = request.getParameter("page");
if(strPage == null)
intPage = 1;//若没有page参数,此时显示第一页的记录
else
intPage = Integer.parseInt(strPage);//显示第intPage页
rs.last();//游标在最后一行
intRowCount = rs.getRow();
intPageCount = (intRowCount+intPageSize-1)/intPageSize;//计算总页数
if(intPage>intPageCount) intPage = intPageCount;//调整待显示的页码
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>通知公告</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="view.jsp" method="post">
<tr>
<td>news_no</td>
<td>title</td>
</tr>
<tr>
<td><%=rs.getString("news_no") %></td>
<td><%=rs.getString("title") %></td>
</tr>
</form>
</body>
<%
if(rs!=null){
try {
rs.close();
rs = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
if(stmt!=null){
try {
stmt.close();
stmt = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
if(con!=null){
try{
con.close();
con = null;
}catch(SQLException ex) {
System.err.println(ex.getMessage());
System.out.println("-------------------数据库关闭失败!");
}
}
%>
</html>