------=_Part_14364_21795484.1208958370464
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
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
------=_Part_14364_21795484.1208958370464
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
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:<br>
<br> try
{<br> s
=
conn.createStatement();<br>
log.info("Got
Connection");<br><br>
empID = s.executeQuery("SELECT nextval(emp_uid) FROM
employee"); <--- this is not working<br>
log.info("Got Employee ID
");<br>
<br>
empID.next();<br>
int newID =
empID.getInt(1);<br>
log.info("New ID = " +
newID);<br>
<br> rows
= s.executeUpdate("INSERT INTO employee(emp_uid,first_name, last_name,
emp_nbr, emp_type_code, emp_status_code, emp_work_center) " +<br>
"VALUES
('"+newID+"','"+firstName+"','"+lastName+"','"+empNumber+"','"+empType+"','"+empStatus+"','"+workStation+
"')");<br>
<br> } catch (SQLException se)
{<br>
log.info("We got an exception while executing our query:"
+<br>
"that probably means our SQL is invalid. " +<br>
se);<br>
System.exit(1);<br>
}<br><br>Here's the log:<br><br><div style="margin-left: 40px;">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<br>
</div><br>What am I missing?<br><br>Thank You<br>Chris<br>
------=_Part_14364_21795484.1208958370464--


|