Thread: Problems with getLastOID

Problems with getLastOID

From
first last
Date:
Hi everyone. I am new to this list so I will introduce myself before I
ask anything.

My name is Gabriel and I work as a developer. I first used Postgres
during my dissertation at
 university and now I have chosen it for a project at work (not the
first time I get to use it
 professionally). I like to use well tested and documented code :)

Now for the question:

I am accessing Postgres 7.2.1, the official Debian package in woody
with Sun's JSDK 1.4.1
and the 1.4 JDBC drivers from the Postgres site.

I got an example from the libpgjava Debian package that I can not get
to compile, it
complains that:
basic.java:90: cannot resolve symbol
symbol  : method getLastOID  ()
location: interface java.sql.Statement
                long insertedOID = ((Statement)st).getLastOID();

I used javap on java.sql.Statement and I can't find getLastOID nor any
other method that will return me the ID of the last inserted.

Any help would be welcome, I will need the id soon.

Thanks very much

Gabriel

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Re: Problems with getLastOID

From
Dave Cramer
Date:
Gabriel,

Ya, you have to cast the statement to a
org.postgresql.AbstractJdbc1Statement to call that method

this is an exerpt from grep OID ...

AbstractJdbc1Statement.java:    public long getLastOID() throws
SQLException
AbstractJdbc1Statement.java:            return
((AbstractJdbc1ResultSet)result).getLastOID();

DAve

On Thu, 2003-02-20 at 08:47, first last wrote:
> Hi everyone. I am new to this list so I will introduce myself before I
> ask anything.
>
> My name is Gabriel and I work as a developer. I first used Postgres
> during my dissertation at
>  university and now I have chosen it for a project at work (not the
> first time I get to use it
>  professionally). I like to use well tested and documented code :)
>
> Now for the question:
>
> I am accessing Postgres 7.2.1, the official Debian package in woody
> with Sun's JSDK 1.4.1
> and the 1.4 JDBC drivers from the Postgres site.
>
> I got an example from the libpgjava Debian package that I can not get
> to compile, it
> complains that:
> basic.java:90: cannot resolve symbol
> symbol: method getLastOID  ()
> location: interface java.sql.Statement
>                 long insertedOID = ((Statement)st).getLastOID();
>
> I used javap on java.sql.Statement and I can't find getLastOID nor any
> other method that will return me the ID of the last inserted.
>
> Any help would be welcome, I will need the id soon.
>
> Thanks very much
>
> Gabriel
>
> __________________________________________________
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
--
Dave Cramer <Dave@micro-automation.net>


Re: Problems with getLastOID

From
Anders Hermansen
Date:
Or even better cast to org.postgresql.PGStatement
But maybe the getLastOID() is not in that interface for all versions?
It is in mine anyway...


Anders

* Dave Cramer (Dave@micro-automation.net) wrote:
> Gabriel,
>
> Ya, you have to cast the statement to a
> org.postgresql.AbstractJdbc1Statement to call that method
>
> this is an exerpt from grep OID ...
>
> AbstractJdbc1Statement.java:    public long getLastOID() throws
> SQLException
> AbstractJdbc1Statement.java:            return
> ((AbstractJdbc1ResultSet)result).getLastOID();
>
> DAve
>
> On Thu, 2003-02-20 at 08:47, first last wrote:
> > Hi everyone. I am new to this list so I will introduce myself before I
> > ask anything.
> >
> > My name is Gabriel and I work as a developer. I first used Postgres
> > during my dissertation at
> >  university and now I have chosen it for a project at work (not the
> > first time I get to use it
> >  professionally). I like to use well tested and documented code :)
> >
> > Now for the question:
> >
> > I am accessing Postgres 7.2.1, the official Debian package in woody
> > with Sun's JSDK 1.4.1
> > and the 1.4 JDBC drivers from the Postgres site.
> >
> > I got an example from the libpgjava Debian package that I can not get
> > to compile, it
> > complains that:
> > basic.java:90: cannot resolve symbol
> > symbol: method getLastOID  ()
> > location: interface java.sql.Statement
> >                 long insertedOID = ((Statement)st).getLastOID();
> >
> > I used javap on java.sql.Statement and I can't find getLastOID nor any
> > other method that will return me the ID of the last inserted.
> >
> > Any help would be welcome, I will need the id soon.
> >
> > Thanks very much
> >
> > Gabriel
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Everything you'll ever need on one web page
> > from News and Sport to Email and Music Charts
> > http://uk.my.yahoo.com
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster
> --
> Dave Cramer <Dave@micro-automation.net>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org


Re: Problems with getLastOID

From
first last
Date:
I have tried and now it can't find
org.postgresql.AbstractJdbc1Statement (I tried that one before but I
forgot to specify the whole path of the class).

basic.java:90: cannot resolve symbol
symbol  : class AbstractJdbc1Statement
location: package postgresql
                long insertedOID =
((org.postgresql.AbstractJdbc1Statement)st).getInsertedOID();

some more information I forgot before, my CLASSPATH is

/usr/local/tomcat/common/lib/servlet.jar
:/usr/local/tomcat/shared/classes
:/usr/local/tomcat/server/lib/pg73jdbc3.jar
:.

I have also tried with the pg72jdbc2.jar driver and both give me the
same error.

JAVA_HOME=/usr/local/java (which links to /usr/local/j2sdk1.4.1). I
also have
CATALINA_HOME as I am using tomcat (that's why the jdbc jar is in that
directory).

Any more ideas?

Thanks

Gabriel

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Re: Problems with getLastOID

From
first last
Date:
Can't get that one either. The surprising thing is that the rest of the
interface works and it actually connects and inserts, etc.

 --- Anders Hermansen <anders@yoyo.no> wrote: > Or even better cast to
org.postgresql.PGStatement
> But maybe the getLastOID() is not in that interface for all versions?
> It is in mine anyway...
>
>

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Re: Problems with getLastOID

From
Anders Hermansen
Date:
* first last (prelude_2_murder@yahoo.co.uk) wrote:
> I have tried and now it can't find
> org.postgresql.AbstractJdbc1Statement (I tried that one before but I
> forgot to specify the whole path of the class).

org.postgresql.jdbc1.AbstractJdbc1Statement

but you should really try to use org.postgresql.PGStatement instead.


Anders

--
Anders Hermansen
YoYo Mobile as

Re: Problems with getLastOID

From
Dave Cramer
Date:
Gabriel,

Please not that my reference was to getLastOID(), not getInsertedOID()

Dave
On Thu, 2003-02-20 at 09:28, first last wrote:
> I have tried and now it can't find
> org.postgresql.AbstractJdbc1Statement (I tried that one before but I
> forgot to specify the whole path of the class).
>
> basic.java:90: cannot resolve symbol
> symbol: class AbstractJdbc1Statement
> location: package postgresql
>                 long insertedOID =
> ((org.postgresql.AbstractJdbc1Statement)st).getInsertedOID();
>
> some more information I forgot before, my CLASSPATH is
>
> /usr/local/tomcat/common/lib/servlet.jar
> :/usr/local/tomcat/shared/classes
> :/usr/local/tomcat/server/lib/pg73jdbc3.jar
> :.
>
> I have also tried with the pg72jdbc2.jar driver and both give me the
> same error.
>
> JAVA_HOME=/usr/local/java (which links to /usr/local/j2sdk1.4.1). I
> also have
> CATALINA_HOME as I am using tomcat (that's why the jdbc jar is in that
> directory).
>
> Any more ideas?
>
> Thanks
>
> Gabriel
>
> __________________________________________________
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
--
Dave Cramer <Dave@micro-automation.net>


Re: Problems with getLastOID (updated, it now compiles)

From
first last
Date:
Thanks, I already tried that too.

I changed my CLASSPATH to include the jdbc jar first and I got it to
compile with org.postgresql.ResultSet but now it dies when I try to run
it with:

Connecting to Database URL = jdbc:postgresql:back_office
Connected...Now creating a statement

Running tests:
Exception caught.
java.lang.ClassCastException: org.postgresql.jdbc2.Statement
java.lang.ClassCastException: org.postgresql.jdbc2.Statement
        at basic.doexample(basic.java:91)
        at basic.<init>(basic.java:44)
        at basic.main(basic.java:210)

which makes me think that there has to be something wrong with my
setup, as the path you gave me before was jdbc1. It sounds like
somewhere I have some other libraries that conflict with this...

I will keep on trying...

 --- Dave Cramer <Dave@micro-automation.net> wrote: > Gabriel,
>
> Please not that my reference was to getLastOID(), not
> getInsertedOID()
>
> Dave
> On Thu, 2003-02-20 at 09:28, first last wrote:
> > I have tried and now it can't find
> > org.postgresql.AbstractJdbc1Statement (I tried that one before but
> I
> > forgot to specify the whole path of the class).
> >
> > basic.java:90: cannot resolve symbol
> > symbol: class AbstractJdbc1Statement
> > location: package postgresql
> >                 long insertedOID =
> > ((org.postgresql.AbstractJdbc1Statement)st).getInsertedOID();
> >
> > some more information I forgot before, my CLASSPATH is
> >
> > /usr/local/tomcat/common/lib/servlet.jar
> > :/usr/local/tomcat/shared/classes
> > :/usr/local/tomcat/server/lib/pg73jdbc3.jar
> > :.
> >
> > I have also tried with the pg72jdbc2.jar driver and both give me
> the
> > same error.
> >
> > JAVA_HOME=/usr/local/java (which links to /usr/local/j2sdk1.4.1). I
> > also have
> > CATALINA_HOME as I am using tomcat (that's why the jdbc jar is in
> that
> > directory).
> >
> > Any more ideas?
> >
> > Thanks
> >
> > Gabriel
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Everything you'll ever need on one web page
> > from News and Sport to Email and Music Charts
> > http://uk.my.yahoo.com
> >
> > ---------------------------(end of
> broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster
> --
> Dave Cramer <Dave@micro-automation.net>
>

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Re: Problems with getLastOID (updated, it now compiles)

From
Dave Cramer
Date:
Cast it to that, it should work, ie org.postgresql.jdbc2.Statement

Dave

On Thu, 2003-02-20 at 11:07, first last wrote:
> Thanks, I already tried that too.
>
> I changed my CLASSPATH to include the jdbc jar first and I got it to
> compile with org.postgresql.ResultSet but now it dies when I try to run
> it with:
>
> Connecting to Database URL = jdbc:postgresql:back_office
> Connected...Now creating a statement
>
> Running tests:
> Exception caught.
> java.lang.ClassCastException: org.postgresql.jdbc2.Statement
> java.lang.ClassCastException: org.postgresql.jdbc2.Statement
>         at basic.doexample(basic.java:91)
>         at basic.<init>(basic.java:44)
>         at basic.main(basic.java:210)
>
> which makes me think that there has to be something wrong with my
> setup, as the path you gave me before was jdbc1. It sounds like
> somewhere I have some other libraries that conflict with this...
>
> I will keep on trying...
>
>  --- Dave Cramer <Dave@micro-automation.net> wrote: > Gabriel,
> >
> > Please not that my reference was to getLastOID(), not
> > getInsertedOID()
> >
> > Dave
> > On Thu, 2003-02-20 at 09:28, first last wrote:
> > > I have tried and now it can't find
> > > org.postgresql.AbstractJdbc1Statement (I tried that one before but
> > I
> > > forgot to specify the whole path of the class).
> > >
> > > basic.java:90: cannot resolve symbol
> > > symbol: class AbstractJdbc1Statement
> > > location: package postgresql
> > >                 long insertedOID =
> > > ((org.postgresql.AbstractJdbc1Statement)st).getInsertedOID();
> > >
> > > some more information I forgot before, my CLASSPATH is
> > >
> > > /usr/local/tomcat/common/lib/servlet.jar
> > > :/usr/local/tomcat/shared/classes
> > > :/usr/local/tomcat/server/lib/pg73jdbc3.jar
> > > :.
> > >
> > > I have also tried with the pg72jdbc2.jar driver and both give me
> > the
> > > same error.
> > >
> > > JAVA_HOME=/usr/local/java (which links to /usr/local/j2sdk1.4.1). I
> > > also have
> > > CATALINA_HOME as I am using tomcat (that's why the jdbc jar is in
> > that
> > > directory).
> > >
> > > Any more ideas?
> > >
> > > Thanks
> > >
> > > Gabriel
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Everything you'll ever need on one web page
> > > from News and Sport to Email and Music Charts
> > > http://uk.my.yahoo.com
> > >
> > > ---------------------------(end of
> > broadcast)---------------------------
> > > TIP 4: Don't 'kill -9' the postmaster
> > --
> > Dave Cramer <Dave@micro-automation.net>
> >
>
> __________________________________________________
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
--
Dave Cramer <Dave@micro-automation.net>


Re: Problems with getLastOID

From
Barry Lind
Date:
Gabriel,

 From the looks of the code posted, and the circumstances you are
reporting it looks like the following:

a) you are running the 7.3 jdbc drivers
b) you are running code written to the 7.2 jdbc drivers

The code below is casting the statement to an org.postgresql.Statement.
  In 7.3 that interface was renamed to org.postgresql.PGStatement.

It should be as simple as changing:

                 long insertedOID = ((Statement)st).getLastOID();
to
                 long insertedOID = ((PGStatement)st).getLastOID();

(you might also need to change an import).

thanks,
--Barry


first last wrote:
> Hi everyone. I am new to this list so I will introduce myself before I
> ask anything.
>
> My name is Gabriel and I work as a developer. I first used Postgres
> during my dissertation at
>  university and now I have chosen it for a project at work (not the
> first time I get to use it
>  professionally). I like to use well tested and documented code :)
>
> Now for the question:
>
> I am accessing Postgres 7.2.1, the official Debian package in woody
> with Sun's JSDK 1.4.1
> and the 1.4 JDBC drivers from the Postgres site.
>
> I got an example from the libpgjava Debian package that I can not get
> to compile, it
> complains that:
> basic.java:90: cannot resolve symbol
> symbol  : method getLastOID  ()
> location: interface java.sql.Statement
>                 long insertedOID = ((Statement)st).getLastOID();
>
> I used javap on java.sql.Statement and I can't find getLastOID nor any
> other method that will return me the ID of the last inserted.
>
> Any help would be welcome, I will need the id soon.
>
> Thanks very much
>
> Gabriel
>
> __________________________________________________
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>



Re: Problems with getLastOID

From
first last
Date:
I am running the Java 2 PostgreSQL 7.2.x  driver, downloaded from
jdbc.postgresql.org.

The code is the example code that comes with the Debian libpgjava
package (JDBC driver), which I use to test when I install (the last
time it was a long time ago, with 7.1).

I am not importing anything from org.porstgresql, maybe that is the
reason, but I am importing java.sql. If I try to import
org.porstgresql.org it clashes in Statement and Connection.

For what I can see the Statement version in java.sql does not have all
the methods that the one in org.postgresql has, that is where I get the
errors.

I will just keep on using the whole path when I need to.

What should I import to get the driver going? I thought that just using
the class.forName ("org.postgresql.Driver") would do it (at least it
worked all the other times I have used it, maybe I have been lucky).

Thanks for your help :)

Gabriel

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Re: Problems with getLastOID

From
Dave Cramer
Date:
Gabriel,

You are doing it correctly, don't import org.posgtresql into your
source. Just cast the statement to org.postgresql.PGStatement as
java.sql.Statement does not specify this method. This is a postgres
specific extension.

Loading the driver is correct too!

Dave
On Fri, 2003-02-21 at 05:38, first last wrote:
> I am running the Java 2 PostgreSQL 7.2.x  driver, downloaded from
> jdbc.postgresql.org.
>
> The code is the example code that comes with the Debian libpgjava
> package (JDBC driver), which I use to test when I install (the last
> time it was a long time ago, with 7.1).
>
> I am not importing anything from org.porstgresql, maybe that is the
> reason, but I am importing java.sql. If I try to import
> org.porstgresql.org it clashes in Statement and Connection.
>
> For what I can see the Statement version in java.sql does not have all
> the methods that the one in org.postgresql has, that is where I get the
> errors.
>
> I will just keep on using the whole path when I need to.
>
> What should I import to get the driver going? I thought that just using
> the class.forName ("org.postgresql.Driver") would do it (at least it
> worked all the other times I have used it, maybe I have been lucky).
>
> Thanks for your help :)
>
> Gabriel
>
> __________________________________________________
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
--
Dave Cramer <Dave@micro-automation.net>