Subject Run batch script (multiple inserts)?
Author mailmur
[JRE1.4, Jaybird, Firebird1.5, Win2k]
We have MSSQL db where we can run batch scripts through a
general "execute(sql)" method call. Now we tried similar query in
Firebird but it failed.

My site has " http://koti.mbnet.fi/akini/ib/ " has a small
testprogram, see at the end of page. Javatest client has a tweaked
runScript() method where we split each INSERT line to separate
statements and then run it.

Batch script has "Declare var" commands, several updates and insert
rows. It is generated automatically and then run as stmt.execute(sql)
method. Works perfectly in MSSQL jdbc driver. Scripts are
autogenerated based on several input parameters.

Not even simple version work in Jaybird/Firebird. If we dont have any
variable declarations but only two INSERT rows still it does not
work. It seems it fails immediately on second INSERT line.

How can I run a batch scriptfile through Jaybird driver?
thx

>>>>>>>>>
[Very simple script, does not work in FB but fine in MSSQL]
INSERT INTO Customers VALUES(1, 1001, 'CustFin', 'Känkkäränkkä',
123.456, '1');
INSERT INTO Customers VALUES(2, 1002, 'CustFin', 'Röxör City ÅÄÖ',
456.789, @var);
INSERT INTO Customers VALUES(3, 1003, 'CustRus', 'Saiperia ЗИ&#=
1049;',
111, '1');

>>>>>>>>>>>>>>
[scrip does not work in FB but fine in MSSQL]
Declare @var nvarchar(1)
set @var='0'
INSERT INTO Customers VALUES(1, 1001, 'CustFin', 'Känkkäränkkä',
123.456, '1');
INSERT INTO Customers VALUES(2, 1002, 'CustFin', 'Röxör City ÅÄÖ',
456.789, @var);
INSERT INTO Customers VALUES(3, 1003, 'CustRus', 'Saiperia ЗИ&#=
1049;',
111, '1');
INSERT INTO Customers VALUES(4, 1004, 'CustGreek', 'Hella ΨΩΪ=
;', 222,
@var);
INSERT INTO Customers VALUES(9999, 9999, 'TheOne', 'ÅÄÖ ЗИh=
9; ΨΩΪ ٤٧٩
ßŴǾ', 111, '1');

>>>>>>>>>>>>>>>
[runScript() method to run batch scripts]
public void runScript() throws Exception {
String sql = readFile("script.txt");

con.setAutoCommit(false);
try {
Statement stmt = null;
try {
stmt = con.createStatement();
boolean b = stmt.execute(sql);
} finally {
if (stmt != null)
try { stmt.close(); } catch (Exception ex) { }
}
con.commit();
} catch (Exception ex) {
con.rollback();
throw ex;
} finally {
try { con.setAutoCommit(true); } catch (Exception ex) { }
}
}

>>>>>>>>>>>>>>>>>>
[Exception thrown from Jaybird]
Exception in thread "main" org.firebirdsql.jdbc.FBSQLException: GDS
Exception.
Dynamic SQL Error
SQL error code = -104
Token unknown - line 2, char 1
INSERT
at org.firebirdsql.jdbc.FBStatement.execute(FBStatement.java:527)
at FBRead.runScript(FBRead.java:97)
at FBRead.main(FBRead.java:120)
at org.firebirdsql.gds.GDSException: Dynamic SQL Error SQL error
code = -104
Token unknown - line 2, char 1
INSERT
at org.firebirdsql.jgds.GDS_Impl.readStatusVector(GDS_Impl.java:1698)
at org.firebirdsql.jgds.GDS_Impl.receiveResponse(GDS_Impl.java:1651)
at org.firebirdsql.jgds.GDS_Impl.isc_dsql_prepare(GDS_Impl.java:1162)
at org.firebirdsql.jca.FBManagedConnection.prepareSQL
(FBManagedConnection.java:767)
at org.firebirdsql.jdbc.FBConnection.prepareSQL
(FBConnection.java:1110)
at org.firebirdsql.jdbc.FBStatement.prepareFixedStatement
FBStatement.java:998)
at org.firebirdsql.jdbc.FBStatement.internalExecute
(FBStatement.java:986)
at org.firebirdsql.jdbc.FBStatement.execute(FBStatement.java:518)
at FBRead.runScript(FBRead.java:97)
at FBRead.main(FBRead.java:120)


>>>>>>>>>>>>>>>>
ps:
Firebirdsql_full.jar has an empty MANIFEST.MF file so dont know which
driver revision I use. Filedate is 2003-08-10 (yyyy-mm-dd).