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 Sql > Re: error codes
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 3416 of 3799
Post > Topic >>

Re: error codes

by craig@[EMAIL PROTECTED] (Craig Ringer) Apr 17, 2008 at 06:43 PM

Marcin Krawczyk wrote:
> Hi guys. Does anyone know the error code for '/currval of sequence * is
> not yet defined in this session/' error ? Is there one at all?

A quick JDBC test program shows:

ERROR: currval of sequence "customer_id_seq" is not yet defined in this
session (SQLState: 55000)

which, looking up the error code in the docs:

http://www.postgresql.org/docs/current/static/errcodes-appendix.html

turns out to be:

55000	OBJECT NOT IN PREREQUISITE STATE

.... which makes sense, but I wouldn't call blindingly and immediately
obvious.



Here's a trivial little utility for running a statement, catching an
error, and re****ting the error along with the Pg error code. Sorry for
the horrible formatting (short lines for email).

--- Put in file `JdbcTest.java' ---

im****t java.sql.SQLException;
im****t java.sql.CallableStatement;
im****t java.sql.Connection;
im****t java.sql.DriverManager;

class JdbcTest  {

    public static void main(String[] args)
      throws ClassNotFoundException, InterruptedException, SQLException
    {
        Class.forName("org.postgresql.Driver");
        Connection c =
          DriverManager.getConnection("jdbc://YOUR_PARAMS_HERE");
        try {
            CallableStatement st =
                c.prepareCall("SELECT currval('customer_id_seq')");
            st.execute();
        } catch (SQLException ex) {
            System.out.println(
                "DB error string: " + ex.getMessage()
                 + " (SQLState: " + ex.getSQLState() + ")");
        }
    }
}

---- end ----

You'll need the PostgreSQL JDBC driver.

To compile (assuming you don't use a Java IDE of some sort, but have the
JDK installed) run:

   javac -d /out/dir JdbcTest.java

and to run (all on one line):

java -classpath /path/to/postgresql-8.3-603.jdbc4.jar:/out/dir JdbcTest

where /out/dir is wherever you want the generated .class file to be put.

--
Craig Ringer

-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 3 Posts in Topic:
error codes
jankes.mk@[EMAIL PROTECTE  2008-04-17 10:23:30 
Re: error codes
craig@[EMAIL PROTECTED]   2008-04-17 18:43:16 
Re: error codes
craig@[EMAIL PROTECTED]   2008-04-17 18:51:12 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Mon Dec 1 22:05:48 CST 2008.