tags:

views:

219

answers:

1

I need to be able to execute (via JDBC) a straightforward SQL select query against a view (the view can be generated via a fairly complex source query). Here's the catch: I don't have write access to the database, so I can't create the view there.

Is anyone aware of a JDBC proxy that will let you define a view against the underlying database? The database happens to be MSSQL, if that helps, but bonus points for a db-agnostic proxy.

Certainly I can implement my own as a brute-force solution, but I would much prefer to avoid re-inventing the wheel if there's a solution out there already.

For purposes of this question, assume that read-only db access and querying the JDBC driver against the view schema (with no end-user knowledge of the underlying db schema) are non-negotiable.

A: 

You can use what is called an inline view, using a subselect:

SELECT *
  FROM (SELECT *
          FROM ...) x

In this example, x is the table alias. What goes on within the brackets is the inline view - it can be whatever valid SQL statement to represent the view you need for your situation. It's not reuseable in the sense that a typical SQL view would be, but it's less effort than whatever infrastructure you're proposing to create.

OMG Ponies
To add, the subselect/inline view is executed *first*
OMG Ponies