如果是报错SQLException,那是因为:
if a database access error occurs or the result set type is TYPE_FORWARD_ONLY

解决方案 »

  1.   

    如果要用到last()和beforeFirst()之类,那么在创建Statement的时候要设置参数
    Connection.createStatement(int resultSetType,int resultSetConcurrency)
    第一个参数
    resultSetType 
    =ResultSet.TYPE_FORWARD_ONLY       游标只能往前,即只能用next(),不能用previous()
    =ResultSet.TYPE_SCROLL_INSENSITIVE 游标可以双向滚动
    =ResultSet.TYPE_SCROLL_SENSITIVE   游标可以双向滚动,而且结果集是实时更新的
    第二个参数
    resultSetConcurrency
    =ResultSet.CONCUR_READ_ONLY 返回只读结果集
    =ResultSet.CONCUR_UPDATABLE 返回可更新的结果集
      

  2.   

    Statement stmt=conn.createStatement() //默认不给参数的话,是不能回滚的.给个参数createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);参考doccreateStatement
    public Statement createStatement(int resultSetType,
                                     int resultSetConcurrency)
                              throws SQLExceptionCreates a Statement object that will generate ResultSet objects with the given type and concurrency. This method is the same as the createStatement method above, but it allows the default result set type and concurrency to be overridden. 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
      

  3.   

    你看看这样行的通吗?
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);