db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dag Wanvik <dag.wan...@oracle.com>
Subject Re: How to emit DDL programmatically using dblook?
Date Mon, 15 Oct 2012 12:58:44 GMT

On 15.10.2012 13:03, Dinesh Bajaj wrote:
> Hi,
> I am struggling to emit DDL of a Derby database programmatically. So
> far, I was using dblook tool at the command prompt to generate the
> DDL. Now, I need to do it through code, and I can't  find a method in
> the dblook class that I could invoke to accomplish this task.
> Sorry, if this question sounds silly.

I am not sure we have a API for this, but you could try to call dblook
from your app directily:
This worked for me:

public static void main(String[] args) throws SQLException {
        Connection c =
        Statement s = c.createStatement();
        s.executeUpdate("create table t (i int)");
        String args2[] = { "-d", "jdbc:derby:wombat"};

giving this on system out:

-- Timestamp: 2012-10-15 14:55:57.548
-- Source database is: wombat
-- Connection URL is: jdbc:derby:wombat
-- appendLogs: false

-- ----------------------------------------------
-- DDL Statements for tables
-- ----------------------------------------------


By proving an "-o" argument you could redirect this to a file and pick
it up from your app.
Hope this helps,

> Thanks,
> Dinesh

View raw message