总是报错:Result set type is TYPE_FORWARD_ONLY

redking1234 2009-06-13 04:08:59
在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>
...全文
292 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiheia 2009-06-14
  • 打赏
  • 举报
回复
第一,无意之中看到的。
String sql = "use cy select * from news";
有这样的sql语句吗,不会报语法错误吗???

第二,LZ可以尝试将
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
中的2个参数去掉
stmt=con.createStatement();
看还有错吗?
lgq_0714 2009-06-13
  • 打赏
  • 举报
回复
将错误信息贴出来看看!!
sangshusen_1988 2009-06-13
  • 打赏
  • 举报
回复
不知道楼主使的啥数据库,如果是access的话估计就不支持这种操作了,
是否可滚动跟数据库有关系的

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧