public int getTutorById() { openConnection(); int tutor_id = 0; try { Statement stmt3 = connection.createStatement(); ResultSet rs = stmt3.executeQuery("SELECT last_insert_id() from xtutor"); { while (rs.next()) { tutor_id = rs.getInt(1); } } } catch (SQLException e) { e.printStackTrace(); } return tutor_id; }
org.postgresql.util.PSQLException: ERROR: function last_insert_id() does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts. Position: 8 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365) at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:307) at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:293) at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:270) at org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:224) at daoMySql.tutorDAOImpl.getTutorById(tutorDAOImpl.java:202) at daoMySql.tutorDAOImpl.getAlltutors(tutorDAOImpl.java:161) at business.manager.getAlltutors(manager.java:99)
The generated id is successfully generated by JDBC.
The errors when I tested in out using PGAdmin4 is
ERROR: function last_insert_id() does not exist LINE 1: SELECT last_insert_id() from xtutor; ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SQL state: 42883 Character: 8