Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Interfaces Jdbc > Filtering out c...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 1901 of 1984
Post > Topic >>

Filtering out commas for DOUBLE

by Chris Gamache <cgamache@[EMAIL PROTECTED] > Mar 4, 2008 at 02:20 PM

I was having a problem with JDBC expecting a DOUBLE from a PostgreSQL
function which returnes "money" ... My first inclination was to return
an OTHER, but PgJDBC balks that it expects java.sql.Types=8 (DOUBLE)
but I set it to 1111 (OTHER) ... There was (seemingly) no way around
that.

So, I decided to attack the root of the problem: PostgreSQL is
returning "1,234.00" when it is executing the function that returns
money and JDBC won't budge on it's expectation that it should be
DOUBLE. The comma in the return string is confusing
Double.parseDouble, so I filter out the commas before parseDouble is
called. My hack got me over the hump, but it makes me uneasy to apply
this patch to a codebase that I am not intimately familiar with. Can
you propose a different way around this problem, a more complete
patch, or the blessing that this will not adversely affect the normal
function of the driver?

From org.postgresql.jdbc2.AbstractJdbc2ResultSet:

    public static double toDouble(String s) throws SQLException
    {
        if (s != null)
        {
            try
            {
                s = s.trim();
                s = s.replace(",",""); //filter out the commas
                return Double.parseDouble(s);
            }
            catch (NumberFormatException e)
            {
                throw new PSQLException(GT.tr("Bad value for type
{0} : {1}", new Object[]{"double",s}),
 
PSQLState.NUMERIC_VALUE_OUT_OF_RANGE);
            }
        }
        return 0;  // SQL NULL
    }




 2 Posts in Topic:
Filtering out commas for DOUBLE
Chris Gamache <cgamach  2008-03-04 14:20:33 
Re: Filtering out commas for DOUBLE
books@[EMAIL PROTECTED]   2008-03-05 18:34:52 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Fri Jul 4 9:47:39 CDT 2008.