Subject Re: [Firebird-Java] arithmetic exception, numeric overflow, or string truncation
Author Roman Rokytskyy
> What may cause this error?

I see following possibilities:

a) a sum(...) is bigger than 2^63-1, that could include only values visible
in that transaction, so they could reproduce it and you couldn't. That would
be numeric overflow.

b) "futar" variable was too long. That would be string truncation.

> How come I get a arithmetic exception, numeric overflow, or string
> truncation from a while(rs.next()) ?

No idea. I would expect it to happen during execute, but it also can be that
server started to evaluate query on the first fetch (that would be the a)
case)... But no clue, one has to check the server behavior for this query.

> I am sure that select sum(order_value) doesn't give back a number
> larger than long

Then I have no other ideas... Maybe Firebird-Support would be more
helpful...

> ps: If you want, you can freely criticise my coding, I actually
> appreciate it :)

a) I use prepared statements instead of concatenation. First, "futar" can
contain single-quote for example, that will cause error during statement
preparation. Second, connection pool might also cache prepared statements,
so that would increase the performance.

b) I use the try/finally blocks for connections and statements:

Connection conn = ds.getConnection();
try {
Statement stmt = conn.createStatement();
try {
....
} finally {
stmt.close();
}
} finally {
conn.close();
}

That guarantees that resources are always freed, even when exception happens
(which in does not happen in your code).

> btw Roman, does the RC2 jaybird support backing up without
> username/pass in case of embedded?

I did not do anything there, since there were no bug report and I did not
(and do not) remember that this was raised here. But I just checked the
code - you're right, it causes NPE if no user name and password is
specified. Will be fixed in final release.

But it won't help you - server expects either SYSDBA or db owner account
even in embedded mode. So, you have to fill a feature request for Firebird
Embedded instead.

Thanks!
Roman