Changeset 283

Show
Ignore:
Timestamp:
04/15/08 10:29:39 (9 months ago)
Author:
chris
Message:

Another SQL DATE fix, this time for getString().

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lex/trunk/src/com/qwirx/db/sql/SqlDatabase.java

    r281 r283  
    489489        } 
    490490    } 
     491     
     492    /** 
     493     * Ugly hack replacement for ResultSet.getString() because 
     494     * getString() doesn't work for 0000-00-00 values, and  
     495     * noDatetimeStringSync=true returns empty string instead of 
     496     * 0000-00-00 contrary to the docs.  
     497     * @param columnNum 
     498     * @return 
     499     * @throws SQLException 
     500     */ 
     501    public static Object getObject(int columnNum, 
     502                ResultSet rs) 
     503    throws SQLException 
     504    { 
     505        // FIXME date 0000-00-00 in a MySQL database causes 
     506        // an exception when we call getString() on it 
     507 
     508        try 
     509        { 
     510                return rs.getObject(columnNum); 
     511        } 
     512        catch (SQLException e) 
     513        { 
     514                if (e.getMessage().equals("Value '0000-00-00' " + 
     515                "can not be represented as java.sql.Date")) 
     516                { 
     517                        return "0000-00-00"; 
     518                } 
     519 
     520                throw e; 
     521        } 
     522    } 
     523 
     524    /** 
     525     * Ugly hack replacement for ResultSet.getString() because 
     526     * getString() doesn't work for 0000-00-00 values, and  
     527     * noDatetimeStringSync=true returns empty string instead of 
     528     * 0000-00-00 contrary to the docs.  
     529     * @param columnName 
     530     * @param rs 
     531     * @return 
     532     * @throws SQLException 
     533     */ 
     534    public static Object getObject(String columnName, 
     535                ResultSet rs) 
     536    throws SQLException 
     537    { 
     538        // FIXME date 0000-00-00 in a MySQL database causes 
     539        // an exception when we call getString() on it 
     540 
     541        try 
     542        { 
     543                return rs.getObject(columnName); 
     544        } 
     545        catch (SQLException e) 
     546        { 
     547                if (e.getMessage().equals("Value '0000-00-00' " + 
     548                "can not be represented as java.sql.Date")) 
     549                { 
     550                        return "0000-00-00"; 
     551                } 
     552 
     553                throw e; 
     554        } 
     555    } 
    491556}