Re: JDBC question: Which class is returned?

From: Barry Lind <barry(at)xythos(dot)com>
To: "Dr(dot) Evil" <drevil(at)sidereal(dot)kz>
Cc: pgsql-jdbc(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: JDBC question: Which class is returned?
Date: 2001-10-15 16:37:41
Message-ID: 3BCB10D5.3030603@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

It should be returning an Integer object. In a brief look at the source
code it seems to be doing the correct thing. What version are you using?

Also I noticed your example below:

System.out.println("The result is: " + (String) obj);

This shouldn't work. You can't cast any random object to a String. I
think what you want is:

System.out.println("The result is: " + obj.toString());

thanks,
--Barry

Dr. Evil wrote:

> I am doing some queries using JDBC. I use the ResultSet.getObject()
> method to get the result object. This works fine with SQL VARCHAR,
> etc, but there is a big problem when I try it with an INT4.
>
> For example:
>
> Object obj = result.getObject(i);
>
> It gets the object just fine but then I can't do anything with the
> object. I can't do this:
>
> System.out.println("The result is: " + (String) obj);
>
> or anything else. I am guessing that the problem may be that it is
> trying to return an integer type, which is not an object. Any
> sugestions on this?
>
> One thing I think I could do is to try to detect the type using
> MetaData.getResultType() or something, and then call
> ResultSet.getInt() or whatever is appropriate. Is this the best way
> to do it?
>
> Thanks
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Gould 2001-10-15 17:14:58 Re: interbase v postgresql
Previous Message John P. Looney 2001-10-15 16:36:46 Re: writing & flushing C extensions

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dario Silva Prieto 2001-10-15 19:10:31 Urgent problems with my conection
Previous Message Mihai Gheorghiu 2001-10-15 13:56:28 Fw: [GENERAL] Error messages