From: Csaba Nagy <nagy@ecircle-ag.com>
To: Ravi Chaddha <ravi_chaddha@yahoo.co.in>
Cc: Postgres JDBC <pgsql-jdbc@postgresql.org>
Subject: Re: SQL Script using JDBC
Date: Mon, 06 Feb 2006 11:01:06 +0100
Message-ID: <1139220066.24321.188.camel@coppola.muc.ecircle.de> (raw)
In-Reply-To: <20060206094141.15194.qmail@web8805.mail.in.yahoo.com>
References: <20060206094141.15194.qmail@web8805.mail.in.yahoo.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: nagy@ecircle-ag.com, ravi_chaddha@yahoo.co.in
Subject: Re: SQL Script using JDBC
In-Reply-To: <1139220066.24321.188.camel@coppola.muc.ecircle.de>
References: <20060206094141.15194.qmail@web8805.mail.in.yahoo.com> <1139220066.24321.188.camel@coppola.muc.ecircle.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox