You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Dinesh Bajaj <di...@ymail.com> on 2012/10/15 13:03:58 UTC

How to emit DDL programmatically using dblook?

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.

Thanks,
Dinesh

Re: How to emit DDL programmatically using dblook?

Posted by Dinesh Bajaj <di...@ymail.com>.
Hi Rick,

I missed your response altogether. Yes, what you suggest works. Thanks!

-Dinesh


________________________________
 From: Rick Hillegas <ri...@oracle.com>
To: derby-user@db.apache.org 
Sent: Monday, 15 October 2012 6:13 PM
Subject: Re: How to emit DDL programmatically using dblook?
 
On 10/15/12 4:03 AM, 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.
Hi Dinesh,

You can invoke dblook.main with your arguments. Something like this should work:

    dblook.main( new String[] { "-d", "jdbc:derby:db", "-o", "dblook.out" } );

Hope this helps,
-Rick
> 
> Sorry, if this question sounds silly.
> 
> Thanks,
> Dinesh
> 
> 
> 

Re: How to emit DDL programmatically using dblook?

Posted by Rick Hillegas <ri...@oracle.com>.
On 10/15/12 4:03 AM, 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.
Hi Dinesh,

You can invoke dblook.main with your arguments. Something like this 
should work:

     dblook.main( new String[] { "-d", "jdbc:derby:db", "-o", 
"dblook.out" } );

Hope this helps,
-Rick
>
> Sorry, if this question sounds silly.
>
> Thanks,
> Dinesh
>
>
>


Re: How to emit DDL programmatically using dblook?

Posted by Dinesh Bajaj <di...@ymail.com>.
Thanks for your reply, Dag.

Yes, your advice did help, and I generated a file containing the DDL commands :-) Many thanks!

I too had thought of invoking the main method of dblook, but then decided against it thinking that the main method is meant to be invoked by the runtime only.

-Dinesh



________________________________
 From: Dag Wanvik <da...@oracle.com>
To: Derby Discussion <de...@db.apache.org> 
Sent: Monday, 15 October 2012 6:28 PM
Subject: Re: How to emit DDL programmatically using dblook?
 



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 =
    DriverManager.getConnection("jdbc:derby:wombat;create=true");
        Statement s = c.createStatement();
        s.executeUpdate("create table t (i int)");
        String args2[] = { "-d", "jdbc:derby:wombat"};
        dblook.main(args2);
        
    }

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
-- ----------------------------------------------

CREATE TABLE "APP"."T" ("I" INTEGER);

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




>
>Thanks,
>Dinesh
>
>
>
>
>
>

Re: How to emit DDL programmatically using dblook?

Posted by Dag Wanvik <da...@oracle.com>.
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 =
DriverManager.getConnection("jdbc:derby:wombat;create=true");
        Statement s = c.createStatement();
        s.executeUpdate("create table t (i int)");
        String args2[] = { "-d", "jdbc:derby:wombat"};
        dblook.main(args2);
       
    }

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
-- ----------------------------------------------

CREATE TABLE "APP"."T" ("I" INTEGER);

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


>
> Thanks,
> Dinesh
>
>
>