Re: Is it possible to call find the number of columns in a JDBC query without executing it?
From: Robert Klemme (bob.news_at_gmx.net)
Date: 02/23/04
- Previous message: Jeff Smith: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- In reply to: Jeff Smith: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Next in thread: Joe Weinstein: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 23 Feb 2004 18:07:08 +0100
Sorry for jumping in lately. I might repeat things that have been said
before.
"Jeff Smith" <jsmit234 at ford dot com> schrieb im Newsbeitrag
news:c1cv6r$47h6@eccws12.dearborn.ford.com...
> That is a good solution (David Harper's forcing query to execute but
return
> nothing). You may also be able to actually query the database system
tables
> for column and/or counts. In Oracle's case, all_tab_columns. Other
dbms's
> should have similar tables, but you definitely lose portability this
way.
>
> This still involves an actual *query* of some kind being round-tripped,
> albeit very quick.
That's what DatabaseMetaData is for:
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Connection.html#getMetaData()
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/DatabaseMetaData.html
The downside is that is easy only for queries like "select * from foo"
i.e. when you simply draw data from a table, but it doesn't work well for
real queries which might involve conversions of column types, joins etc.
> Jeff
>
> "David Harper" <devnull@obliquity.u-net.com> wrote in message
> news:Jw6Zb.54$m47.9@newsfe1-win...
> > Geoff Hardy wrote:
> >
> > > Is it possible to call find the number of columns in a query without
> > > executing it?
> > [SNIP]
> >
> > You could try appending "LIMIT 1" to your query, then you *can*
execute
> > it, safe in the knowledge that you aren't about to suck a couple of
> > gigabytes of data out of Oracle just to count the columns.
When talking about portability, wouldn't it be better to add something
like "1 = 0" (i.e. always false) to the WHERE clause? IMHO this is more
portable than using LIMIT or TOP (MS SQL Server) and ensures that the
result set is empty, too.
> > The metadata for the limited query will be the same as for the full
query.
Yes.
robert
- Previous message: Jeff Smith: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- In reply to: Jeff Smith: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Next in thread: Joe Weinstein: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|