Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Interfaces Jdbc > Creating a sequ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 1935 of 1994
Post > Topic >>

Creating a sequence

by cmattmiller@[EMAIL PROTECTED] (Chris) Apr 23, 2008 at 08:46 AM

------=_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.&nbsp; I&#39;ve read that I need to create a sequence first,
but I&#39;m not sure how to go about doing that with an existing
table.&nbsp; Here is the code I have so far:<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try
{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s
=
conn.createStatement();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
log.info(&quot;Got
Connection&quot;);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
empID = s.executeQuery(&quot;SELECT nextval(emp_uid) FROM
employee&quot;);&nbsp;&nbsp;&nbsp; &lt;--- this is not working<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
log.info(&quot;Got Employee ID
&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
empID.next();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
int newID =
empID.getInt(1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
log.info(&quot;New ID = &quot; +
newID);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rows
= s.executeUpdate(&quot;INSERT INTO employee(emp_uid,first_name, last_name,
emp_nbr, emp_type_code, emp_status_code, emp_work_center) &quot; +<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&quot;VALUES
(&#39;&quot;+newID+&quot;&#39;,&#39;&quot;+firstName+&quot;&#39;,&#39;&quot;+lastName+&quot;&#39;,&#39;&quot;+empNumber+&quot;&#39;,&#39;&quot;+empType+&quot;&#39;,&#39;&quot;+empStatus+&quot;&#39;,&#39;&quot;+workStation+&nbsp;
&quot;&#39;)&quot;);<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (SQLException se)
{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
log.info(&quot;We got an exception while executing our query:&quot;
+<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&quot;that probably means our SQL is invalid.&nbsp; &quot; +<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
se);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.exit(1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}<br><br>Here&#39;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--
 




 4 Posts in Topic:
Creating a sequence
cmattmiller@[EMAIL PROTEC  2008-04-23 08:46:10 
Re: Creating a sequence
craig@[EMAIL PROTECTED]   2008-04-23 23:00:44 
Re: Creating a sequence
craig@[EMAIL PROTECTED]   2008-04-23 23:04:22 
Re: Creating a sequence
craig@[EMAIL PROTECTED]   2008-04-24 01:00:51 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Sun Jul 20 4:32:06 CDT 2008.