1

我曾经执行过这个查询没有任何问题,但最近我遇到了异常。

(在 mysql 服务器上)

48442 [NioProcessor-1] ERROR c.x.xpofacebook.mysql.MysqlDb - SQLException: Before start of result set
48443 [NioProcessor-1] ERROR c.x.xpofacebook.mysql.MysqlDb - SQLState: S1000
48443 [NioProcessor-1] ERROR c.x.xpofacebook.mysql.MysqlDb - VendorError: 0
48451 [NioProcessor-1] ERROR c.x.xpofacebook.mysql.MysqlDb - stack trace: java.sql.SQLException: Before start of result set

编码:

String createPlayerRow = "insert into highscore_challenge_player "
            + "(fb_user_id,played,best_score,highscore_challenge_id) values ((select fb_user.id from fb_user where uid=?),?,?,?)";
        stmt.close();
        stmt = conn.prepareStatement(createPlayerRow,Statement.RETURN_GENERATED_KEYS);
        stmt.setLong(1, uid);
        stmt.setInt(2, 0);
        stmt.setInt(3, 0);
        stmt.setInt(4, highscoreChallengeId);
        stmt.executeUpdate();
        rs = stmt.getGeneratedKeys();
        rowId = rs.getInt(1); <--- ERROR IN THIS LINE    

有任何想法吗 ?!?

谢谢

4

1 回答 1

2

您需要先获得第一个结果,然后才能开始查看其中的项目。

更明确地说:您需要rs.next()至少调用一次才能访问结果。更一般的,需要调用nextn次才能查看第n行,加上sql结果,count从1开始,而不是0。

于 2010-11-07T16:05:32.553 回答