sql jdbc getgeneratedkeys returns column “id” not found, column type unknown

前端 未结 2 1595
感动是毒
感动是毒 2020-12-06 06:51

I want to retrieve the most recently updated value in the table using an insert query.

these are the datatypes in my sql table.

Datatype:

相关标签:
2条回答
  • 2020-12-06 07:31

    You need to call rs.next():

    int autoIncKeyFromApi = -1;
    rs = stmt.getGeneratedKeys();
    if (rs.next()) {
        autoIncKeyFromApi = rs.getInt(1);
    } else {
        // do what you have to do
    }
    System.out.println(autoIncKeyFromApi);
    
    0 讨论(0)
  • 2020-12-06 07:46

    Maybe it's because that the sqlQuery doesn't create any new record! In this case, it will return an empty ResultSet Look at the specification of getGeneratedKeys()

    0 讨论(0)
提交回复
热议问题