Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Creating a sequence



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


Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group