当你打开一个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 

解决方案 »

  1.   

    可以的,用first(),就可以了。
      

  2.   

    楼上老兄:写完下面语句后报错..."未定义变量:TYPE_SCROLL_INSENSITIVE"conn = DriverManager.getConnection(sConnStr,"sa",""); //连接数据库stmt=conn.createStatementTYPE_SCROLL_INSENSITIVE,CONCUR_READ_ONLY);
    //创建statement实例
    请问这是什么原因...
      

  3.   

    把TYPE_SCROLL_INSENSITIVE,CONCUR_READ_ONLY的包名也指出来
      

  4.   

    把TYPE_SCROLL_INSENSITIVE改成TYPE_SCROLL_SENSITIVE。对滚动支持才对吗。
      

  5.   

    to sunhawk(黑鹰):
    请问怎样才能指出TYPE_SCROLL_INSENSITIVE,CONCUR_READ_ONLY的包呢?我用的是jsp...我是这样写的...
    <%@page import="java.sql.*"%>
    还不行么?...
    to yhc0125(小程):
    TYPE_SCROLL_SENSITIVE我也试过了...
    也抱错:"未定义变量:TYPE_SCROLL_SENSITIVE"
      

  6.   

    试试
    java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE
    java.sql.ResultSet.CONCUR_UPDATABLE
    如果还不行,那就是你设置的classpath有问题。
      

  7.   

    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。