Re: PreparedStatement
From: Peter (peter_at_ciber)
Date: 01/08/04
- Next message: Peter: "Re: PreparedStatement"
- Previous message: Simon: "JDO: persist Object with reference to another"
- In reply to: Virgil Green: "Re: PreparedStatement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 8 Jan 2004 21:39:56 +0100
Hi, thanks for the comments...
> NUMBER in an Oracle database corresponds to, as I recall, BigDecimal. But
I
> haven't done it in a while. It actually depends upon what JDBC driver
you're
> using. There should be documentation identifying the mappings between Java
> and Oracle datatypes for that JDBC driver along with the correct setXxx()
> method to use.
Yes, when I read from the table, I can see that the Object type is
BigDecimal.
But the "generic database access" class I am using to insert data to the
database doesn't know that, as it receives all the parameters as String
objects. The class gets all the parameters in a List (each object in the
List is a String), and does this:
pstmt.setObject( i, nextParam );
in a loop for the list of parameters. Some of the parameters are actually
numeric values. It works fine for columns which do not take a "fractional"
part, but fails for numbers like 28.2.
It appears that the setObject method (or maybe the database itself) is happy
to insert Strings into numeric fields (as long as the Strings are numbers,
like "34" of course), except if the field is for decimal numbers (ie with a
fractional part) ?
It would obviously be much better just to be able to supply a BigDecimal
object in the List of parameters, and then setObject can work out the
conversion (I've tried it, it works great). Unfortunately I am stuck between
the class that delivers the data (as a List of Strings), and the class that
writes to the database. So either I should redesign the whole database
access part of the application (which I would love to do, but would require
lots of testing with many existing parts of the system), or use some sort of
specific kludge (which my boss will approve of cause it won't take so long
to hack a nasty addition for this specific circumstance...)
Thanks,
Peter
- Next message: Peter: "Re: PreparedStatement"
- Previous message: Simon: "JDO: persist Object with reference to another"
- In reply to: Virgil Green: "Re: PreparedStatement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|