Bug #7601 PreparedStatement.fixDecimalExponent fails if number is already valid.
Submitted: 31 Dec 2004 12:20 Modified: 18 Jan 2005 21:36
Reporter: Janne Hietamäki Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:3.0.16ga OS:Linux (Linux)
Assigned to: Mark Matthews CPU Architecture:Any

[31 Dec 2004 12:20] Janne Hietamäki
Description:
Java 1.5 returns BigDecimal.toString() sometimes in exponent form (1.5E+7), this causes problems in com.mysql.jdbc.PreparedStatement.

Connector/J tries to fix the decimals, but actually brokes them is they already are valid.

From source:

 //
 // Adds '+' to decimal numbers that are positive (MySQL doesn't
 // understand them otherwise
 //
   private static final String fixDecimalExponent(String dString) {
 

How to repeat:
Code:

    System.out.println(fixDecimalExponent(new BigDecimal("1.5E+7")));
returns:

1.5E++7

Which is not valid value for MySQL.

Suggested fix:
replace line:

if (maybeMinusChar != '-'){

to:

if (maybeMinusChar != '-' && maybeMinusChar!='+') {
[18 Jan 2005 21:36] Mark Matthews
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html