From derby-user-return-14681-apmail-db-derby-user-archive=db.apache.org@db.apache.org Mon Oct 15 12:59:19 2012 Return-Path: X-Original-To: apmail-db-derby-user-archive@www.apache.org Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 48E2FDB10 for ; Mon, 15 Oct 2012 12:59:19 +0000 (UTC) Received: (qmail 60230 invoked by uid 500); 15 Oct 2012 12:59:18 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 59895 invoked by uid 500); 15 Oct 2012 12:59:18 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 59868 invoked by uid 99); 15 Oct 2012 12:59:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Oct 2012 12:59:17 +0000 X-ASF-Spam-Status: No, hits=-2.8 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_HI,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of dag.wanvik@oracle.com designates 141.146.126.227 as permitted sender) Received: from [141.146.126.227] (HELO acsinet15.oracle.com) (141.146.126.227) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Oct 2012 12:59:05 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by acsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q9FCwgCL030308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 15 Oct 2012 12:58:43 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q9FCwfKK015593 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 15 Oct 2012 12:58:42 GMT Received: from abhmt104.oracle.com (abhmt104.oracle.com [141.146.116.56]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q9FCwfwa001295 for ; Mon, 15 Oct 2012 07:58:41 -0500 Received: from [10.172.139.222] (/10.172.139.222) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2012 05:58:41 -0700 Message-ID: <507C0884.6000005@oracle.com> Date: Mon, 15 Oct 2012 14:58:44 +0200 From: Dag Wanvik Organization: Oracle Corporation User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: Derby Discussion Subject: Re: How to emit DDL programmatically using dblook? References: <1350299038.75255.YahooMailNeo@web162702.mail.bf1.yahoo.com> In-Reply-To: <1350299038.75255.YahooMailNeo@web162702.mail.bf1.yahoo.com> Content-Type: multipart/alternative; boundary="------------070200060501080200030902" X-Source-IP: ucsinet21.oracle.com [156.151.31.93] X-Virus-Checked: Checked by ClamAV on apache.org This is a multi-part message in MIME format. --------------070200060501080200030902 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 > > > --------------070200060501080200030902 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
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




--------------070200060501080200030902--