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

  • Next message: Rob: "searching for a nice database"
    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


  • Next message: Rob: "searching for a nice database"

    Relevant Pages

    • Re: Finally which ORM tool?
      ... manipulate the linq query IF you're executing it at that moment. ... simply because the declaration construction was with 'CHOPS'. ... implement IEnumerablebut had an Execute() method which gave back ...
      (microsoft.public.dotnet.languages.csharp)
    • RE: SQL stored procedure executing twice
      ... I wasn't aware that DLookupwould execute the "domain" more than once. ... caused the stored procedure to execute twice. ... Dim stDocName As String ... My pass-thru query properties ...
      (microsoft.public.access.modulesdaovba)
    • Re: Clarification on DBI module
      ... You get the same results for the second execute because the record buffer in the statment handle is not cleaned out because no execute took place. ... The sql query can have bind variables or they may not have. ... Ahhh...imagining that irresistible "new car" smell? ...
      (perl.dbi.users)
    • Re: UPDATE query in Access 2003 raising error
      ... Runtime error 3066 Query must have at least one destination field. ... The SQL works fine if I use it in the QBF Design mode. ... Set qdfTemp = db.CreateQueryDef ... Elsewhere in the code I use the same technique to execute an SQL ...
      (microsoft.public.access.formscoding)
    • Re: Primary Key Violation Error Message
      ... I should have read your query more carefully. ... > Dim ws As DAO.Workspace 'Current workspace (for transaction). ... > 'Step 2: Execute the append. ...
      (microsoft.public.access.formscoding)