如何把ResultSet中的指针放到指定的位置
int size=0;
try{
while(rs.next()){
size+=1;
}
}catch(SQLException e){
System.out.println(e.toString());
}
这段程序执行后,rs的指针是否已经在最后一行了。如何把指针再放回到初始位置呢?
int size=0;
try{
while(rs.next()){
size+=1;
}
}catch(SQLException e){
System.out.println(e.toString());
}
这段程序执行后,rs的指针是否已经在最后一行了。如何把指针再放回到初始位置呢?
解决方案 »
- 请问怎么让java程序在后台运行
- 请高手看看哪里出错了,一个简单的java正则表达式问题
- 关于重载的,我以为我懂了,结果又蒙了,请大家指教一下!
- j2se程序执行顺序
- 谁能解释一下jode反编译的代码:class$com$BizDicManager 和class$("com.BizDicManager")
- 广州请进,为MM找工作,无以答谢,赠送劳动力免费开发项目以答谢,诚心
- !急啊 立刻给分!weblogic.ant.taskdefs.ejb.DDInit生成xml时出错信息!什么原因?
- 简单的问题,来抢分
- 怎样通过程序打开网站浏览
- 关于事件互相调用的问题
- java问题:如何把数字转换成汉字
- 一首面试题
RS.isAfterLast() //是否最后一行
RS.beforeFirst(); //回到最前一行
rs.first()可以移动,但与记录集类型有关,有的是不能返回的
void afterLast() 将指针移动到此 ResultSet 对象的末尾,正好位于最后一行之后
void beforeFirst() 将指针移动到此 ResultSet 对象的开头,正好位于第一行之前
boolean first() 将指针移动到此 ResultSet 对象的第一行
void afterLast() 将指针移动到此 ResultSet 对象的末尾,正好位于最后一行之后
void beforeFirst() 将指针移动到此 ResultSet 对象的开头,正好位于第一行之前
boolean first() 将指针移动到此 ResultSet 对象的第一行
if(rs.isLast())
System.out.println("aaaaaaaaaa");
else
System.out.println("nnnnnnnnnn");
}catch(SQLException e){
System.out.println(e.toString());
}
我试了一下,错误:unsupported method:ResultSet.isLast。每次我在用rs的一些方法时,比如afterLast() 、first() 之类的,都会出现类似的错误。能告诉我怎么用么?
这里面的参数会有影响static int TYPE_FORWARD_ONLY
The constant indicating the type for a ResultSet object whose cursor may move only forward.
static int TYPE_SCROLL_INSENSITIVE
The constant indicating the type for a ResultSet object that is scrollable but generally not sensitive to changes made by others.
static int TYPE_SCROLL_SENSITIVE
The constant indicating the type for a ResultSet object that is scrollable and generally sensitive to changes made by others.
这里面的参数会有影响static int TYPE_FORWARD_ONLY
The constant indicating the type for a ResultSet object whose cursor may move only forward.
static int TYPE_SCROLL_INSENSITIVE
The constant indicating the type for a ResultSet object that is scrollable but generally not sensitive to changes made by others.
static int TYPE_SCROLL_SENSITIVE
The constant indicating the type for a ResultSet object that is scrollable and generally sensitive to changes made by others.
主要是在创建statement的时候要指定产生的结果是否可以来回的读取
把原来的stmt=conn.createStatement();
改成stmt=conn.createStatement=(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
再把代码改为:就可以了
package aaa;
import java.sql.*;public class a111{
public static void main(String[] args){
javaConnectToSql jcts=new javaConnectToSql();
jcts.Conn("com.microsoft.jdbc.sqlserver.SQLServerDriver","jdbc:microsoft:sqlserver://localhost:1433;databaseName=biyesheji","sa","");
ResultSet rs=null;
rs=jcts.QuerySql("select * from historyInfo where flag=0");
int size=0;
try{
while(rs.next()){
size+=1;
}
}catch(SQLException e){
System.out.println(e.toString());
}
System.out.println(size);//得到size=3;
try{
rs.beforeFirst();
if(size>0){
while(rs.next()){
System.out.println(rs.getString(1));
}
}
else{
while(rs.next()){
System.out.println(rs.getString(2));
}
}
}catch(SQLException e){
System.out.println(e.toString());
}
}
}谢谢各位!!!!!!!!!!!