Next Previous Up Contents
Next: Writing to a Database
Up: I/O using SQL databases
Previous: JDBC Configuration

3.7.2 Reading from a Database

You can view the result of an SQL query on a relational database as a table. This can be done either by passing the query string directly to a JDBCHandler or by passing it to the generic StarTableFactory.makeStarTable method (any string starting 'jdbc:' in the latter case is assumed to be an SQL query string). The form of this query string is as follows:

    jdbc:<driver-specific-url>#<sql-query>
The exact form is dependent on the JDBC driver which is installed. Here is an example for MySQL:
    jdbc:mysql://localhost/astro1?user=mbt#SELECT ra, dec FROM swaa WHERE vmag<18
If the username and/or password are required for the query but are not specified in the query string, they will be prompted for.

Note that the StarTable does not represent the JDBC table itself, but a query on table. You can get a StarTable representing the whole JDBC table with a query like SELECT * from table-name, but this may be expensive for large tables.


Next Previous Up Contents
Next: Writing to a Database
Up: I/O using SQL databases
Previous: JDBC Configuration

STIL - Starlink Tables Infrastructure Library
Starlink User Note 252
STIL web page: http://www.starlink.ac.uk/stil/
Author email: m.b.taylor@bristol.ac.uk
Starlink: http://www.starlink.ac.uk/