当前位置: 技术问答>java相关
关于结果集指针移动问题...
来源: 互联网 发布时间:2015-04-29
本文导语: 请问对应与next()有向上移动指针的函数么?... 例如: exp1="select ........."; ResultSet rs=null; rs=my.executeQuery(exp1); while(rs.next()){ ...... } 执行完后我又想把指针重新移到结果集的顶端,可以么? shenleave@163.net | ...
请问对应与next()有向上移动指针的函数么?...
例如:
exp1="select .........";
ResultSet rs=null;
rs=my.executeQuery(exp1);
while(rs.next()){
......
}
执行完后我又想把指针重新移到结果集的顶端,可以么?
shenleave@163.net
例如:
exp1="select .........";
ResultSet rs=null;
rs=my.executeQuery(exp1);
while(rs.next()){
......
}
执行完后我又想把指针重新移到结果集的顶端,可以么?
shenleave@163.net
|
cranberry、idpmud、itok000正解。
修改
stmt=conn.createStatementTYPE_SCROLL_INSENSITIVE,CONCUR_READ_ONLY);
为
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
TYPE_SCROLL_SENSITIVE比TYPE_SCROLL_INSENSITIVE少了synchronize,如果你需要同步修改/查询数据库的话,可以使用TYPE_SCROLL_SENSITIVE;否则为了效率可使用TYPE_SCROLL_INSENSITIVE。
修改
stmt=conn.createStatementTYPE_SCROLL_INSENSITIVE,CONCUR_READ_ONLY);
为
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
TYPE_SCROLL_SENSITIVE比TYPE_SCROLL_INSENSITIVE少了synchronize,如果你需要同步修改/查询数据库的话,可以使用TYPE_SCROLL_SENSITIVE;否则为了效率可使用TYPE_SCROLL_INSENSITIVE。
|
当你打开一个statement的时候,可以选择不同的类型,可以达到你的目的!
createStatement
public Statement createStatement(int resultSetType,
int resultSetConcurrency)
throws SQLExceptionCreates a Statement
Parameters:
resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
Returns:
a new Statement object that will generate ResultSet objects with the given type and concurrency
Throws:
SQLException - if a database access error occurs or the given parameters are not ResultSet constants indicating type and concurrency
Since:
1.2
createStatement
public Statement createStatement(int resultSetType,
int resultSetConcurrency)
throws SQLExceptionCreates a Statement
Parameters:
resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
Returns:
a new Statement object that will generate ResultSet objects with the given type and concurrency
Throws:
SQLException - if a database access error occurs or the given parameters are not ResultSet constants indicating type and concurrency
Since:
1.2
|
可以的,用first(),就可以了。
|
试试
java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE
java.sql.ResultSet.CONCUR_UPDATABLE
如果还不行,那就是你设置的classpath有问题。
java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE
java.sql.ResultSet.CONCUR_UPDATABLE
如果还不行,那就是你设置的classpath有问题。
|
把TYPE_SCROLL_INSENSITIVE,CONCUR_READ_ONLY的包名也指出来