Thread: JDBC query...

JDBC query...

From
Mark Dzmura
Date:
Folks:

I would like to extend my (JDBC-using) software to be able to present the user with a list
of available databases from a chosen database server, to create new databases, and to
create new tables...

My reading of the JDBC 1.0 and 2.0 specs presents a picture of an API which seems to be
of a "read only" nature regarding database metadata - I can't find ways to create, delete, and
modify above the level of SQL queries against tables...

In that regard, my questions address both JDBC itself, and the Postgres JDBC driver implementation.

Regarding JDBC,

1. Is there an object of higher "scope" than the Connection object, which is bound to a specific
database??

2. Is there a Database object, which provides methods to create, destroy, and modify the schemas
of tables ??  Or can I do SQL "CREATE TABLE" and "DROP TABLE" operations using some
version of Statement which doesn't return a ResultSet ??

Finally, at what level does the Postgres JDBC driver support JDBC (regarding my questions and
in general) ??

Thanks,
Mark Dzmura

--
)))) This email routed via a wireless gateway!! ((((





Re: [INTERFACES] JDBC query...

From
Herouth Maoz
Date:
At 02:18 +0300 on 13/08/1999, Mark Dzmura wrote:


>1. Is there an object of higher "scope" than the Connection object, which
>is bound to a specific database??

A connection object is bound to one connection to a single database. If you
want to create or delete databases, you have to connect to the PostgreSQL
database named 'template1'. You will typically have a separate connection
object for this.

>2. Is there a Database object, which provides methods to create, destroy,
>and modify the schemas of tables ?? Or can I do SQL "CREATE TABLE" and
>"DROP TABLE" operations using some version of Statement which doesn't
>return a ResultSet ??

Yes, you can use statements such as CREATE TABLE, DROP TABLE, and any other
DDL statement, by using the executeUpdate() method of Statement or
PreparedStatement. Its name may suggest that it is only for UPDATE
statements, but that's not true. It's for any query which is not expected
to return a result set.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma




Re: [INTERFACES] JDBC query...

From
Peter Mount
Date:
On Thu, 12 Aug 1999, Mark Dzmura wrote:

> Folks:
> 
> I would like to extend my (JDBC-using) software to be able to present
> the user with a list of available databases from a chosen database
> server, to create new databases, and to create new tables...
> 
> My reading of the JDBC 1.0 and 2.0 specs presents a picture of an API
> which seems to be of a "read only" nature regarding database metadata
> - I can't find ways to create, delete, and modify above the level of
> SQL queries against tables...
> 
> In that regard, my questions address both JDBC itself, and the
> Postgres JDBC driver implementation.
> 
> Regarding JDBC,
> 
> 1. Is there an object of higher "scope" than the Connection object,
> which is bound to a specific database??

No. Connection is created by Driver when a connection is made, and
everything else runs from under it.

> 2. Is there a Database object, which provides methods to create,
> destroy, and modify the schemas of tables ??  Or can I do SQL "CREATE
> TABLE" and "DROP TABLE" operations using some version of Statement
> which doesn't return a ResultSet ??

You can use either Statement or PreparedStatement to create tables. You
use the executeUpdate() method, as it doesn't return a ResultSet.

The basic example included with the source creates and drops some tables
in this way.

> Finally, at what level does the Postgres JDBC driver support JDBC
> (regarding my questions and in general) ??

We support the basic parts of both JDBC 1.2 and JDBC 2.0 specs. There is a
lot more to be implemented, but it's currently done on a first come or
spare time basis.

Peter

--      Peter T Mount peter@retep.org.uk     Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgresJava PDF Generator: http://www.retep.org.uk/pdf