0

In PostgreSQL user is a reserved keyword that is used in an internal table, however I also have a separate user table in my own database that I need to use. Whenever I try to execute INSERT or UPDATE statements on the table, it generates the following error: The column name 'id' was not found in this ResultSet.

This is the Java code I am currently using:

PreparedStatement stat1 = conn.prepareStatement("SELECT id FROM user;");
PreparedStatement stat2 = conn.prepareStatement("UPDATE user SET date_created = ? , last_updated = ? , uuid = ? WHERE id = ?;");
ResultSet rs = stat1.executeQuery();
while(rs.next()){
    UUID uuid = UUID.randomUUID();
    String tempId = uuid.toString();

    stat2.setTimestamp(1, curDate);
    stat2.setTimestamp(2, curDate);
    stat2.setString(3, tempId);
    stat2.setLong(4,rs.getLong("id"));

    stat2.executeUpdate();
}

So my question is, how could I insert or update the values in my personal user table without interfering with the keyword restriction?

2 Answers 2

2

Use this:

prepareStatement("UPDATE \"user\" set date_created = ?")

Or, better yet, rename your user table to something else, like users:

ALTER TABLE "user" RENAME TO users;
1

Escape the table name like this

select * from "user";
1
  • thanks @Funtik , now i understand just simple way to escape characters in java. Commented May 29, 2013 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.