Re: PreparedStatement

From: Peter (peter_at_ciber)
Date: 01/08/04


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



Relevant Pages

  • Re: Java, Sql Server & encodings
    ... When you read strings from the database, ... When you finally write these Strings, ... The Servlet container should take care of the proper byte-array encoding. ... Is this conversion normally left up to the JDBC driver ...
    (comp.lang.java.programmer)
  • Re: [ANN] Data Source Name parser (ODBC etc.)
    ... > suggested URL-like strings describing database connections. ... > library for such strings (data source names) is now available at ... raises the exception Syntax_Error. ...
    (comp.lang.ada)
  • Question on how updates to Access tables may or may not cause the database to expand in size
    ... All strings are stored as variable length data, one byte for each actual character and one overhead byte. ... When a database is compacted and repaired, tables are written out in primary key sequence. ... I have concluded that after the compact/repair, that each table, is written in sequence, filling up 2k pages, and that tables are not generally intermixed except at the end of one table and the beginning of the next. ... then the database DOES expand in size. ...
    (comp.databases.ms-access)
  • Re: Japanese to Unicode characters
    ... Oracle-Rdb database; a VB application running on a Window98 Japanese PC ... store the japanese strings as Unicode. ... UniToolBox component for VB which handle the Unicode strings. ...
    (microsoft.public.sqlserver.programming)
  • Re: i18n hell
    ... table attributes to UTF-8 only garbage kept adding into the database. ... you using unicode strings or byte strings? ...
    (comp.lang.python)