SQL-Statement UNLOAD TO and jdbc!!
Posted in 2000
Topics: SQL Development & Query Writing, Connectivity: ODBC / JDBC / .NET, Migration, Import/Export & Data Conversion, Java & JDBC Development
Hi,
I'm working with the informix jdbc driver 2.0. My task is to save tables
to ASCII files.
I found the SQL-Statement:
UNLOAD TO 'filename' SELECT * FROM tablename;
In my code I try to execute this statement in this way:
stm.execute("UNLOAD TO \\'C:\\\\TMP\\\\table.tmp\\' SELECT * FROM table;");
and as:
stm.execute("UNLOAD TO 'C:\\\\TMP\\\\table.tmp' SELECT * FROM table;");
and in a few more variations. The result is always that I receive a
SQL-Exception:
A syntax error has occured
Does anybody has an idea what's the reason for this exception?? Simple
Select statements are working.
Thanx
caroline
In article <38CFABB3.76D52195@siemens.ch>,
"C. Fuchs Bausch" <caroline.fuchs-bausch@siemens.ch> wrote:
> Hi,
>
> I'm working with the informix jdbc driver 2.0. My task is to save
> tables to ASCII files.
>
> I found the SQL-Statement:
> UNLOAD TO 'filename' SELECT * FROM tablename;>
> In my code I try to execute this statement in this way:
>
> stm.execute("UNLOAD TO \\'C:\\\\TMP\\\\table.tmp\\' SELECT * FROM table;");
>
> and as:
>
> stm.execute("UNLOAD TO 'C:\\\\TMP\\\\table.tmp' SELECT * FROM table;");
>
> and in a few more variations. The result is always that I receive a
> SQL-Exception:
>
> A syntax error has occured
>
> Does anybody has an idea what's the reason for this exception?? Simple
> Select statements are working.
>
> Thanx
> caroline
Caroline,
Simple problem: The LOAD and UNLOAD statements are not true SQL
statements. They are utility commands in dbaccess (and isql) as a
convenience but dbaccess does not send these commands to the engine. In
the case of an unload statement, dbaccess sends the SQL part to the
engine and creates the list (with [pipe ]delimiters) itself.
4GL also accepts LOAD and UNLOAD commands and handles them in pretty
much the same way. But you cannot PREPARE an UNLOAD statement, nor can
you use it in a stored procedure.
Solution: Not as easy as explaining the problem.
Obviously, jdbc is not the tool for this function. You could try
running this command in dbaccess or 4GL. Or you could write super-
general formatting code to mimic what dbaccess does. But why reinvent
the wheel?
--
+----- Jacob Salomon - DBA JSalomon@bn.com - --------------------------+
|------------------- Bulletin Board Announcement ----------------------|
| Congregants will please note that the bowl at the back of the church |
| bearing the sign "For the Sick" is for monetary contributions only. |
+----------------------------------------------------------------------+
Sent via Deja.com http://www.deja.com/
Before you buy.
In article <38CFABB3.76D52195@siemens.ch>,
"C. Fuchs Bausch" <caroline.fuchs-bausch@siemens.ch> wrote:
> Hi,
>
> I'm working with the informix jdbc driver 2.0. My task is to save
tables
> to ASCII files.
>
> I found the SQL-Statement:
> UNLOAD TO 'filename' SELECT * FROM tablename;>
> In my code I try to execute this statement in this way:
>
> stm.execute("UNLOAD TO \\'C:\\\\TMP\\\\table.tmp\\' SELECT * FROM table;");
>
> and as:
>
> stm.execute("UNLOAD TO 'C:\\\\TMP\\\\table.tmp' SELECT * FROM table;");
>
> and in a few more variations. The result is always that I receive a
> SQL-Exception:
>
> A syntax error has occured
>
> Does anybody has an idea what's the reason for this exception?? Simple
> Select statements are working.
>
> Thanx
> caroline
>
Like was said before, unload and load are not true sql statements. If
you HAVE to do this through jdbc, you can select the data into a
descriptor. This is kinda difficult, but not that bad. Take a look at
the manual, looking for EXEC SQL ALLOCATE DESCRIPTOR.
--
# unrm /
ksh: unrm: not found
# man cpio
Sent via Deja.com http://www.deja.com/
Before you buy.