Creating a sequence

From: Chris <cmattmiller(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Creating a sequence
Date: 2008-04-23 13:46:10
Message-ID: eac7b0710804230646l5c972dafm6db2369e62e6dcc2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

I have an existing table that I need to get the last record number and
increment it. I've read that I need to create a sequence first, but I'm not
sure how to go about doing that with an existing table. Here is the code I
have so far:

try {
s = conn.createStatement();
log.info("Got Connection");

empID = s.executeQuery("SELECT nextval(emp_uid) FROM
employee"); <--- this is not working
log.info("Got Employee ID ");

empID.next();
int newID = empID.getInt(1);
log.info("New ID = " + newID);

rows = s.executeUpdate("INSERT INTO employee(emp_uid,first_name,
last_name, emp_nbr, emp_type_code, emp_status_code, emp_work_center) " +
"VALUES
('"+newID+"','"+firstName+"','"+lastName+"','"+empNumber+"','"+empType+"','"+empStatus+"','"+workStation+
"')");

} catch (SQLException se) {
log.info("We got an exception while executing our query:" +
"that probably means our SQL is invalid. "
+
se);
System.exit(1);
}

Here's the log:

INFO: We got an exception while executing our query:that probably means our
SQL is invalidorg.postgresql.util.PSQLException: ERROR: could not open
relation with OID 5

What am I missing?

Thank You
Chris

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tom Lane 2008-04-23 14:17:18 Re: Query parameters limit in postgres jdbc driver?
Previous Message olafos 2008-04-23 07:12:45 Query parameters limit in postgres jdbc driver?