View Single Post

   
  #3 (permalink)  
Old 04-24-2008, 06:15 PM
Chris
 
Posts: n/a
Default 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+"','"+emp Number+"','"+empType+"','"+empStatus+"','"+workSta tion+
"')");

} 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

Reply With Quote