X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BF1519DC85C for ; Mon, 6 Feb 2006 06:01:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24686-01 for ; Mon, 6 Feb 2006 06:01:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200]) by postgresql.org (Postfix) with ESMTP id 7E50D9DC84C for ; Mon, 6 Feb 2006 06:01:05 -0400 (AST) Received: from deimos.muc.ecircle.de (deimos.muc.ecircle.de [192.168.1.4]) by mail.ecircle.de (READY) with ESMTP id 00B0155C003; Mon, 6 Feb 2006 11:01:07 +0100 (CET) Received: from [192.168.1.110] ([192.168.1.110]) by deimos.muc.ecircle.de with Microsoft SMTPSVC(5.0.2195.6713); Mon, 6 Feb 2006 11:01:06 +0100 Subject: Re: SQL Script using JDBC From: Csaba Nagy To: Ravi Chaddha Cc: Postgres JDBC In-Reply-To: <20060206094141.15194.qmail@web8805.mail.in.yahoo.com> References: <20060206094141.15194.qmail@web8805.mail.in.yahoo.com> Content-Type: text/plain Message-Id: <1139220066.24321.188.camel@coppola.muc.ecircle.de> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Mon, 06 Feb 2006 11:01:06 +0100 Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 06 Feb 2006 10:01:06.0891 (UTC) FILETIME=[3F5311B0:01C62B04] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.097 required=5 tests=[AWL=0.097] X-Spam-Score: 0.097 X-Spam-Level: X-Archive-Number: 200602/34 X-Sequence-Number: 14631 Ravi, AFAIK, there's no easy way to execute an SQL script directly through JDBC, you will have to write your own parser to split the script in individual statements and execute them one by one. Actually the splitting in statements is the biggest challenge here, it's not as simple as for e.g. using a regular expression. We do this kind of stuff here (i.e. executing SQL scripts through JDBC, with the added condition that the same script must execute fine in psql), and first we used the simple rule of "end of statement = a semicolon at the end of the line". This works fine until your script doesn't contain stored procedures, in that case the stored procedure body is to be sent as one statement, but it surely will contain lines ending in semicolon. So either you start tracking quoted strings, or you use some other statement delimiter. You could use an SQL comment as statement delimiter, something like: -- execute This will be ignored by psql, and used by our parser code to execute the current statement... We actually still use the "line ended with semicolon" delimiter, and put some comments at the end of line in stored procedures to not have the semicolons at line ends... kind of awkward, but it works... HTH, Csaba. On Mon, 2006-02-06 at 10:41, Ravi Chaddha wrote: > Please let me know how can we execute a SQL file using > JDBC from a remote computer. The script creates > tables, functions in PostgreSQL database. > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org