Subject Re: [Firebird-Java] getUpdateCount Problem
Author Gonzalo Odiard
You need code anyway?

>Yes. I see the condition in getUpdateCount()
>
> if (isResultSet || !hasMoreResults)
> return -1;
>
>and assignment hasMoreResults = false happens only in two places:
>getUpdateCount() and hasMoreResults(). Both methods seems to be implemented
>according to the specification.
>
>Roman
>
>
Roman:
We have found the problem.
We do:

public static final int update(DVentaMercadoVO dVentaMercadoVO,
Connection conn) {
int resultado = -1;
try {
if (pstmtUpdate == null) {
String sql = "update dventa_mercados set ct_unidades =
ct_unidades + ?" +
" , cant_recetas = cant_recetas + ?" +
" , monto_mloc = monto_mloc + ?" +
" , monto_mext = monto_mext + ?" +
" where mes_ano = ?" +
" and cod_postal = ?" +
" and cod_mercado = ?" ;
pstmtUpdate = conn.prepareStatement(sql);
}
pstmtUpdate.setInt (1,dVentaMercadoVO.getCtUnidades());
pstmtUpdate.setInt (2,dVentaMercadoVO.getCantRecetas());
pstmtUpdate.setFloat (3,dVentaMercadoVO.getMontoMloc());
pstmtUpdate.setFloat (4,dVentaMercadoVO.getMontoMext());
pstmtUpdate.setString(5,dVentaMercadoVO.getMesAno());
pstmtUpdate.setString(6,dVentaMercadoVO.getCodPostal());
pstmtUpdate.setString(7,dVentaMercadoVO.getCodMercado());

pstmtUpdate.executeUpdate();
resultado = pstmtUpdate.getUpdateCount();

} catch (SQLException e) {
e.printStackTrace();
}
return resultado;
}

But AbstractStatement.executeUpdate do

public int executeUpdate(String sql) throws SQLException {
if(closed)
throw new FBSQLException("Statement is closed");

Object syncObject = getSynchronizationObject();

synchronized(syncObject) {
try {
c.ensureInTransaction();
if (internalExecute(sql)) {
throw new FBSQLException("Update statement returned
results.");
}
return getUpdateCount();
} catch (GDSException ge) {
throw new FBSQLException(ge);
} finally { // end of try-catch
c.checkEndTransaction();
} // end of finally
}
}

then, when we do getUpdateCount, that is the second execution.

We are resolved the problem modifing our code to do:

resultado = pstmtUpdate.executeUpdate();

Anyway, i dont know if this is a bug in AbstractStatement or a bad usage
we do.

Thanks

Gonzalo






[Non-text portions of this message have been removed]