pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedJDBC & custom type of variable types (!)
3+ messages / 3 participants
[nested] [flat]
* JDBC & custom type of variable types (!)
@ 2013-11-27 09:04 Marc Mamin <M.Mamin@intershop.de>
0 siblings, 2 replies; 3+ messages in thread
From: Marc Mamin @ 2013-11-27 09:04 UTC (permalink / raw)
To: pgsql-jdbc
Hello,
I'd like to retrieve a custom type from a result set,
but problem: I don't know exactly the structure.
It may be float/text or int/text, so I'd need to map it to one of those java custom types:
deciType <Double,String>;
intType <Long, String>;
Can I rely on a ClassCastException as below to find the correct matching?
even when the custom type has NULL(s) in it ?
Or is there a better approach ?
case Types.STRUCT:
try
{
foo = (intType)resultset1.getObject(1);
}
catch (ClassCastException e)
{
blah = (deciType)resultset1.getObject(1);
}
(Postgres 9.3 , JDBC4 Postgresql Driver, Version 9.3-1100)
many thanks,
Marc Mamin
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: JDBC & custom type of variable types (!)
@ 2013-11-27 14:02 Dave Cramer <pg@fastcrypt.com>
parent: Marc Mamin <M.Mamin@intershop.de>
1 sibling, 0 replies; 3+ messages in thread
From: Dave Cramer @ 2013-11-27 14:02 UTC (permalink / raw)
To: Marc Mamin <M.Mamin@intershop.de>; +Cc: pgsql-jdbc
I expect that if it has a null you will have a problem, however I'm sure
there is a quick way to test this. Just populate some data with NULL
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Wed, Nov 27, 2013 at 4:04 AM, Marc Mamin <M.Mamin@intershop.de> wrote:
> Hello,
>
> I'd like to retrieve a custom type from a result set,
> but problem: I don't know exactly the structure.
> It may be float/text or int/text, so I'd need to map it to one of those
> java custom types:
>
> deciType <Double,String>;
> intType <Long, String>;
>
>
> Can I rely on a ClassCastException as below to find the correct matching?
> even when the custom type has NULL(s) in it ?
>
> Or is there a better approach ?
>
> case Types.STRUCT:
>
> try
> {
> foo = (intType)resultset1.getObject(1);
> }
> catch (ClassCastException e)
> {
> blah = (deciType)resultset1.getObject(1);
> }
>
> (Postgres 9.3 , JDBC4 Postgresql Driver, Version 9.3-1100)
>
> many thanks,
>
> Marc Mamin
>
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: JDBC & custom type of variable types (!)
@ 2013-11-27 16:13 David Johnston <polobo@yahoo.com>
parent: Marc Mamin <M.Mamin@intershop.de>
1 sibling, 0 replies; 3+ messages in thread
From: David Johnston @ 2013-11-27 16:13 UTC (permalink / raw)
To: pgsql-jdbc
Marc Mamin-2 wrote
> Can I rely on a ClassCastException as below to find the correct matching?
> even when the custom type has NULL(s) in it ?
Even if you could you should not. Generating exceptions is expensive. Try
"instanceof" testing instead.
I don't know enough bounce custom types in JDBC but as the column has the
type, not the value, the result of getObject should be known even if NULL is
involved.
David J.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/JDBC-custom-type-of-variable-types-tp5780512p5780590.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2013-11-27 16:13 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-11-27 09:04 JDBC & custom type of variable types (!) Marc Mamin <M.Mamin@intershop.de>
2013-11-27 14:02 ` Dave Cramer <pg@fastcrypt.com>
2013-11-27 16:13 ` David Johnston <polobo@yahoo.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox