db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Anders Hatlen <Knut.Hat...@Sun.COM>
Subject Re: Why exception exporting parametric query result on Derby ?
Date Mon, 28 Apr 2008 09:00:53 GMT
MikeRam <ing.ramundo@tiscali.it> writes:

> q="SELECT * FROM "+dbTable+" WHERE "+FieldName+" BETWEEN ? AND ? ORDER BY
> ID";
> q="CALL SYSCS_UTIL.SYSCS_EXPORT_QUERY('"+q+"','"+OutFile+"', null, null,
> null)";
> stm=cn.conn.prepareCall(q);
> stm.setString(1, sd.StringDataOraInizio);
> stm.setString(2, sd.StringDataOraFine);
> stm.execute();
>
> I use Apache Derby but,
> When i execute the attached code i receive an exception
> java.sql.SQLException: No input parameters.
>
> Parametric query are usable in stored procedure ?

Derby won't expand parameters within a string literal, so you need to
use the concatenation operator (||) instead. Something like this
(untested) code:

q = "CALL SYSCS_UTIL.SYSCS_EXPORT_QUERY('SELECT * FROM ' || ? || " +
    "' WHERE ' || ? || ' BETWEEN ' || ? ' AND ' || ? || " +
    "' ORDER BY ID', ?, null, null, null)";
stm = cn.conn.prepareCall(q);
stm.setString(1, dbTable);
stm.setString(2, fieldName);
stm.setString(3, sd.StringDataOraInizio);
stm.setString(4, sd.StringDataOraFine);
stm.setString(5, outFile);
stm.execute();

-- 
Knut Anders

Mime
View raw message